3 ms·
> I mean, what happens if the writer thread stalls out in the lock free case? The reader thread runs out of things to do and is also going to be scheduled out (
by chrisseaton 7y ago
> I mean, what happens if the writer thread stalls out in the lock free case? The reader thread runs out of things to do and is also going to be scheduled out (eventually).
Yeah it keeps running, exactly as you say! It can keep working on jobs already on the queue independently.
Are you arguing that you you personally don't think it's worth doing lock-free for various practical reasons? Or arguing that's never why anyone does it?
Because the latter is simply false - I've done it for the latter reasons professionally both in academia and industry so there's one data point for you, and the literature talks about this use-case extensively so I know other people do as well.
- dragontamer 7y ago> Are you arguing that you you personally don't think it's worth doing lock-free for various practical reasons? Or arguing that's never why anyone does it? No. Lock-free is great. When it is done correctly. The code in this blog post was NOT done correctly. It only works in the case of 1-reader + 1-writer, so the "advantages" you're talking about are extremely limited. You have to keep in mind the overall big picture. Lock-free code is incredibly difficult to write and usually comes with great cost to complexity. However... sometimes Lock-free makes life easier (okay, use them in that case). Sometimes, lock-free can be faster (okay... use them in that case... if speed is important to you). But in many, many cases, locked data-structures are just easier to write, test, and debug.
- jcelerier 7y ago> It only works in the case of 1-reader + 1-writer this is what is needed 99.9% of the time. e.g. look at the number of users of this C++ SPSC queue : https://github.com/cameron314/readerwriterqueue https://github.com/cameron314/readerwriterqueue or of the Boost one : https://github.com/search?q=boost%3A%3Alockfree%3A%3Aspsc_queue%3C&type=Code https://github.com/search?q=boost%3A%3Alockfree%3A%3Aspsc_qu...
- dragontamer 7y agoYeah, but the "queue-of-queues" is a more traditional structure familiar to people with lock-free algorithms. I don't have time to do a serious code review of everything... but immediately upon looking at that code, its already clearly written with better quality: with acquire/release fences being used in (seemingly) the correct spot (just as an example). Like, the real issue I have here is the quality of the code that is being demonstrated in the blog post. A lock-free of queues-of-queues implementation makes sense in my brain. What's going on in the blog-post ultimately doesn't make sense.