3 ms·
I don’t understand why I would need to care about this. Can’t my operating system and/or pthread library sort this out by itself?
by EdSchouten 10mo ago
I don’t understand why I would need to care about this. Can’t my operating system and/or pthread library sort this out by itself?
- senderista 10mo agoPretty much, given that any decent pthreads implementation will offer an adaptive mutex. Unless you really need a mutex the size of a single bit or byte (which likely implies false sharing), there's little reason to ever use a pure spinlock, since a mutex with adaptive spinning (up to context switch latency) gives you the same performance for short critical sections without the disastrous worst-case behavior.
- nly 10mo agoSome people don't want to block for a microsecond when their lock goes 1ns over your adaptive mutexes spin deadline. That kind of jitter is unacceptable.
- senderista 10mo agoI assume those people are already running 1 pinned thread/core and have no issues with unbounded spinning in the first place. In which case, go nuts.
- baobun 10mo agoGeneral heuristics only get you so far and at the limit come with their own overhead compared to what you can do with a tailored solution with knowledge about your usage and data access patterns. The cases where this makes a practical difference for higher-level apps are rare but they exist.