Hacker News new | past | comments | ask | show | jobs | submit login

In your dequeue/circular buffer implementation, how is it able to grow the queue without locking?

The code seems to rely on atomics for head & tail, but grows the queue without any special provisions I can see.

https://github.com/mtmucha/coros/blob/ee30d3c1d0602c3071aa26...




The concept behind the deque is explained in Correct and Efficient Work-Stealing for Weak Memory Models [1].

The idea is that only the owning thread can push tasks into the deque. If the owning thread detects that the deque is full, it creates a new one and copies the original values. Once the copy is ready, the owning thread "publishes" it by storing it in the buffer variable. Pointers to the deque are atomic, as well as the indices. Other threads can manipulate only the indices, and even if a stealing thread has an old pointer, it still points to valid data.

I hope I understood your question correctly and that this answer is helpful. You can find more details in the paper mentioned above.

[1] https://inria.hal.science/hal-00802885/document




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: