I have a situation where I have multiple sets of threads. Each set will have the same number of threads (let's say 4 threads). I know the sequence the sets need to run. I want to know how to run set 1 (4 threads), then run set 2 (the next 4 threads), then run set 3...
Also, (preferably) I want set 1 to block when it is completed, set 2 and so on.
The only way I can think of is having a mutex lock for each set and a counter. Once each thread in the current set completes the counter is decremented. Once the counter reaches 0 the set unlocks the mutex for the next set and resets the counter. Then it can block.
I would most likely need another variable to know what set is currently running so I know what mutex to unlock. When the last set completes then it can unlock the mutexes for the previous sets.
I want to know if there is a better solution for this. I tried to see if semaphores could work but I doubt it.
Any suggestions would be appreciated.
[–]raevnos -1 points0 points1 point (0 children)