3 ms·
As long as you have a reasonably modern CPU, you can use one of the various Compare-And-Swap (CAS) instructions to implement properly lock-free FIFO queues. The
by WJW 6y ago
As long as you have a reasonably modern CPU, you can use one of the various Compare-And-Swap (CAS) instructions to implement properly lock-free FIFO queues. There are a few variations but a circular array is one of the possibilities. We can probably discuss for quite some time if it's entirely lock-free if the lock is implemented in hardware but I think we can agree it's not a mutex :)
The people over at enqueuezero have a nice article about lock free queues at https://enqueuezero.com/lock-free-queues.html https://enqueuezero.com/lock-free-queues.html.