Hacker News new | ask | show | jobs
by bitkrieg 4610 days ago
I always hear about how use of mutexes is costly but i never actually encountered a significant performance hit from using synchronization. Unless, of course, you have like 10 threads frequently accessing the same memory, which is more a design issue.
1 comments

Uncontended interlocked operation is typically about 100-300 CPU cycles. Uncontended mutex is about 30x-50x that. If there is contention, multiply everything by another 100x. Additionally these instructions impact not only the calling thread but also other threads by forcing cache synchronization.

Therefore a relatively simple operation like pointer assignment can be one cycle when using GC and a hundred to several thousands cycles when using refcounting. Sometimes you can ignore this overhead, sometimes not - depends on how often you do that.

http://software.intel.com/en-us/articles/choosing-between-sy...

On what CPU? on my i7s it's much faster. on the order of 50 cycles for a uncontended mutex lock and release i think. I can dig out the values if anyone cares.