Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Which lock to use?

    Scheduled Pinned Locked Moved Cinema 4D SDK
    r21r20s22c++macoswindows
    3 Posts 2 Posters 358 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fwilleke80F Offline
      fwilleke80
      last edited by fwilleke80

      Hello,

      there is always something we managed to not get in touch with... for me, it's threading and locks...

      In one of my classes, I have a maxon::KdTree. It is being rebuilt from time to time, depending on some factors. Then there are potentially multiple threads (from maxon::ParallelFor) that want to access the KdTree to call its FindNearest() and FindRange() functions. These have to wait for the tree to be built, of course.

      If I understand the concept of locks correctly, I would need to lock the KdTree while it is being rebuilt. But for the FindNearest() and FindRange() calls, I would need to wait for the KdTree being unlocked, but I would not need to lock it, as those functions are thread safe (if used right), is that correct? So, I looked at the Locks & Synchronization Manual, and I'm not sure which lock to use. It seems, maxon::Spinlock is not what I'm looking for.

      Thanks for any tips & help,
      Frank

      www.frankwilleke.de
      Only asking personal code questions here.

      1 Reply Last reply Reply Quote 0
      • P Offline
        PluginStudent
        last edited by

        What you describe sounds like a job for maxon::RWSpinlock.

        But, FindNearest() and FindRange() are not const, these functions may actually mutate the internal data (you can look at the source in kdtree.cpp). So be sure to use the threadIndex arguments.

        1 Reply Last reply Reply Quote 0
        • fwilleke80F Offline
          fwilleke80
          last edited by

          Always using the threadIndex, of course 🙂
          Thanks, I'll try that!

          www.frankwilleke.de
          Only asking personal code questions here.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post