Sebastian Lackner sebastian@fds-team.de writes:
- Its also on purpose, that num_workers is (read-) accessed at one point
without locking the critical section. If num_workers > 0 we can be sure, that a worker thread will process the work item (sooner or later). If num_workers == 0 we enter the critical section, and check once more to prevent race condition 2.
The worker may be about to exit at the time you check. I don't think it makes any sense to add races to "optimize" an error case that's not going to happen anyway.