Concurrent locks for large number of objects
I'm recursing over about 2000 objects with multiple threads and need to have some locking to prevent two or more threads accessing the same object while it is being processed. I thought of attaching a semaphore to each object and letting the threads acquire it while using the object, which would allow the other threads to block till that object had been processed.
My question is:
1) Is there a better way to handle this case than create 2000+ semaphores
2) Is the memory footprint of the 2000+ semaphores large.