First, locks/mutex do make forward progress. Although they can block a thread, the thread holding the lock makes forward progress and is not waiting on future async work, so the whole thing makes forward progress. This is not the case with semaphores which can be signaled from any thread. That's the big dif…
First, locks/mutex do make forward progress. Although they can block a thread, the thread holding the lock makes forward progress and is not waiting on future async work, so the whole thing makes forward progress. This is not the case with semaphores which can be signaled from any thread. That's the big difference.
About your performance tests:
- to be fair to atomics and mutex, I would recommend switching to a synchronous operation in processAcrossCores(), the async operation has a lot of potential overhead
- you can use atomic.wrappingAdd() instead of add() as the latter generates slower code
- you can replace ProcessInfo.processInfo.activeProcessorCount with the actual number of performance cores on your machine, that might give you more interesting results
Hi Jacob, I have some comments!
First, locks/mutex do make forward progress. Although they can block a thread, the thread holding the lock makes forward progress and is not waiting on future async work, so the whole thing makes forward progress. This is not the case with semaphores which can be signaled from any thread. That's the big difference.
About your performance tests:
- to be fair to atomics and mutex, I would recommend switching to a synchronous operation in processAcrossCores(), the async operation has a lot of potential overhead
- you can use atomic.wrappingAdd() instead of add() as the latter generates slower code
- you can replace ProcessInfo.processInfo.activeProcessorCount with the actual number of performance cores on your machine, that might give you more interesting results