Here, we are going to show an example of a lock-free queue, which is a relatively simple but useful lock-free data structure. Lock-free queues can be used for one-way communication with threads that cannot use locks to synchronize access to shared data.
Its implementation is straightforward because of the limited requirements: it only supports one reader thread and one writer thread. The capacity of the queue is also fixed and cannot change during runtime.
The writer thread is allowed to call:
- push(): adds an element to the queue
The reader thread is allowed to call:
- front(): returns the front element of the queue
- pop(): removes the front element from the queue
Both threads can call:
- size(): returns the current ...