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

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.

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

CyberDildonics|2 years ago

No, where are you getting that information?