logoalt Hacker News

surajrmallast Monday at 4:28 AM4 repliesview on HN

Hybrid locks are also bad for overall system performance by maximizing local application performance. There is a reason default lock implementations from OS don't spin even a little bit.


Replies

menaeruslast Monday at 8:20 AM

> There is a reason default lock implementations from OS don't spin even a little bit.

glibc pthread mutex uses a user-space spinlock to mitigate the syscall cost for uncontended cases.

charleslmungerlast Monday at 9:36 AM

That depends on your workload. If you're making a game that's expected to use near 100% of system resources, or a real time service pinned to specific cores, your local application is the overall system.

show 1 reply
imtringuedlast Monday at 5:58 PM

This is nonsense. If the lock hasn't been acquired, you don't spin to begin with and if the lock has been acquired and the lock is being released shortly after, the spinning avoids a context switch. If the maximum number of retries has been reached, the thread was going to sleep anyway and starts scheduling the next thread (which was only delayed by the few attempted spins). This means in the worst case the next spin will only happen once all the other queued up threads have had their turn and that's assuming you're immediately running into another acquired lock.

show 1 reply
nlylast Monday at 9:44 AM

GNU libc posix mutexes do spin...

show 1 reply