Hacker News new | ask | show | jobs
by devxpy 2863 days ago
Yes, but isn't it more CPU intensive?

(Speaking purely from experience. Don't have a fancy CS degree)

1 comments

It uses 100% CPU, true but when the duration of the lock is extremely small (i.e. nanoseconds->microseconds) the total CPU usage is less than arranging for an OS level context-switch. In other words, you use it when synchronising with hardware or when implementing test-and-set primitives for higher level mechanisms. Crucially, the time that the lock is held for must be very short.

Given those restrictions and use cases you get a very efficient low latency locking mechanism.