Link to home
Start Free TrialLog in
Avatar of PMembrey
PMembrey

asked on

lockless Ring buffer in C

Hi guys,

Another follow up from this post:

https://www.experts-exchange.com/questions/26488392/Atomic-i-in-C.html

Basically, keeping the interface the same, can anyone provide a lockless implementation? i.e. one that does not need mutex or atomic counter updates.

I'm looking for a drop in replacement for the points :-)
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PMembrey
PMembrey

ASKER

Yes, but I'm looking for a solution that I can drop-in in place of the current one - one that does not need a counter.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A completely lock-free circular buffer could be done if there is only one reader and one writer. If you have more than one reader and/or more than one writer, this becomes extremely hard, if not impossible.

I'm not sure what other mechanisms can be added than the ones that phoffric already pointed out. I personally like the solution that keeps one slot free, because it's simple and straightforward to implement.

Please don't award any points to this post, because I'm merely confirming what phoffric already said. I just posted, because you seemed to be waiting for further input before closing the question.
Pity it can't be done but I couldn't see how it would work either. Thanks for confirmation.
That's not what we said : it can be done in several ways. Refer to all the options presented by phoffric :)
A lockless ring buffer that is accessed by multiple reader and writer threads? :)
Ah, ok :)

I was basing my statement on what you said in the related question : "I have written a ring buffer and have one thread reading and one writing."