r/cpp • • May 22 '26

Building a Fast Lock-Free Queue in Modern C++ From Scratch

https://jaysmito.dev/blog/blog/04-fast-lockfree-queues/
135 Upvotes

29 comments sorted by

View all comments

Show parent comment

1

u/Beginning-Safe4282 May 23 '26 edited May 23 '26

To me its usefull if we want to get a rough idea if the que is full or not without some global atomic counter, I know its not accurate as it could be stale by the time it returns the value, and I was Ok with that for the cases it was used, namely deciding whether some worker thread that was sleeping continue to sleep or to wake up.

Its not even needed for the actual queue, its something extra I added just incase any one is interested.

61

u/lxbrtn May 23 '26

wasEmptyVeryRecentlyAndMightStîllBe

11

u/thisismyfavoritename May 23 '26

stîll

1

u/lxbrtn May 23 '26

A little-known introspection cue (off-topic here)

13

u/ericonr May 23 '26

How do you correctly sleep on wasEmpty without impacting latency?

3

u/Beginning-Safe4282 May 23 '26 edited May 23 '26

The point is, you dont, its an extension API just to act as a reference, ideally you dont want to use it in a place where latency is very important, its for cases where a few it or misses are fine