Which lock to use?
-
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 (frommaxon::ParallelFor
) that want to access the KdTree to call itsFindNearest()
andFindRange()
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()
andFindRange()
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 -
What you describe sounds like a job for
maxon::RWSpinlock
.But,
FindNearest()
andFindRange()
are notconst
, these functions may actually mutate the internal data (you can look at the source inkdtree.cpp
). So be sure to use thethreadIndex
arguments. -
Always using the
threadIndex
, of course
Thanks, I'll try that!