top | item 39551328 (no title) liquid153 | 2 years ago Aren't lock free buffers usually just as expensive or more expensive to use as locks. discuss order hn newest loeg|2 years ago No -- for a lock-free design with a single producer and consumer, it's possible both are typically writing to independent regions of memory. With a lock, both have to write the same cache line to take and release the lock. zengid|2 years ago Not if your program needs to be realtime or near realtime safe. Locks are controlled by the OS typically, and can have non-deterministic latency. loeg|2 years ago Even ignoring mutexes and OS scheduling, plain spinlocks add contention that would not otherwise exist in a SPSC ringbuffer. https://news.ycombinator.com/item?id=39551575 ww520|2 years ago Lock free has two advantages: the checking code can run in user mode and non-contested access is very cheap with just one instruction.To do it correctly, lock needs to be done in the kernel thus obtaining a lock requires calling into the kernel which is more expensive.I think you meant the memory barrier for syncing cache is just as expensive as the lock version, which is true. scaredginger|2 years ago Obtaining an uncontested lock absolutely doesn't require calling into the kernel load replies (1) CyberDildonics|2 years ago No, where are you getting that information?
loeg|2 years ago No -- for a lock-free design with a single producer and consumer, it's possible both are typically writing to independent regions of memory. With a lock, both have to write the same cache line to take and release the lock.
zengid|2 years ago Not if your program needs to be realtime or near realtime safe. Locks are controlled by the OS typically, and can have non-deterministic latency. loeg|2 years ago Even ignoring mutexes and OS scheduling, plain spinlocks add contention that would not otherwise exist in a SPSC ringbuffer. https://news.ycombinator.com/item?id=39551575
loeg|2 years ago Even ignoring mutexes and OS scheduling, plain spinlocks add contention that would not otherwise exist in a SPSC ringbuffer. https://news.ycombinator.com/item?id=39551575
ww520|2 years ago Lock free has two advantages: the checking code can run in user mode and non-contested access is very cheap with just one instruction.To do it correctly, lock needs to be done in the kernel thus obtaining a lock requires calling into the kernel which is more expensive.I think you meant the memory barrier for syncing cache is just as expensive as the lock version, which is true. scaredginger|2 years ago Obtaining an uncontested lock absolutely doesn't require calling into the kernel load replies (1)
scaredginger|2 years ago Obtaining an uncontested lock absolutely doesn't require calling into the kernel load replies (1)
loeg|2 years ago
zengid|2 years ago
loeg|2 years ago
ww520|2 years ago
To do it correctly, lock needs to be done in the kernel thus obtaining a lock requires calling into the kernel which is more expensive.
I think you meant the memory barrier for syncing cache is just as expensive as the lock version, which is true.
scaredginger|2 years ago
CyberDildonics|2 years ago