I’m trying to synchronize threads in a critical section, but I need to do it based on a value.
For example if you have threads doing work representing different people (ie bob, fred, bill) then the threads for Bob and Bill could be concurrent, but all of Bob’s threads would be synchronized so that only 1 can go through the critical section at a time. My initial thoughts are to use named mutex, but not sure how to manage them. Perhaps some type of dictionary of named mutexes. Has anyone done something similar?
I’m trying to synchronize threads in a critical section, but I need to do
Share
Personclass representing the person (Bob, Bill, etc.), you canlockon that instance.Person, create aDictionarythat maps unique identifiers of your people to instances of namedMutexobjects. The access to the dictionary itself should be synchronized. Also note that mutex creation in .NET is non-trivial. See this answer for details.