3 ms·
mutexes are not that slow. Uncontested (single thread): incrementing using atomics took 0.002011 s (0.2513 ns / increment) incrementing using mutex took
by Ono-Sendai 3y ago
mutexes are not that slow.
Uncontested (single thread):
incrementing using atomics took 0.002011 s (0.2513 ns / increment)
incrementing using mutex took 0.005515 s (0.6894 ns / increment)
Contested (8 threads trying to increment a single protected integer):
incrementing using atomics took 0.1069 s (13.36 ns / increment)
incrementing using mutex took 1.970 s (246.3 ns / increment)
So mutexes are roughly the same speed in the uncontested case, and about 20x slower in this heavily contested case.
This is on Windows.
- cyberax 3y agoI guess you have more than 8 physical CPUs?
- Ono-Sendai 3y ago16 cores
- mjan22640 3y agoIs that AMD or Intel? Intel ivalidates the other CPU's cache line on write. AMD sends an update to the other CPU's cache line. AMD is supposed to be significantly faster than Intel on a "real" multiprocessor workload.
- Ono-Sendai 3y agoAMD Ryzen 9.
- ComputerGuru 3y agoDon’t know why you were downvoted but yes, AMD uses MOESI and Intel uses MESI.