When using a process with threads, is it possible to use a circular buffer that is not blocked by a mutex?
Even when using an atomic variable, I don't think its possible.
The problem as I see it is if one thread increments the atomic variable, and another thread also increments the variable, it's possible that both threads when interrogating the variable, could come up with the same value.
The best I could come up with was to also utilize a dimensioned array, dimensioned to the size of the circular buffer. Initially these would all be set to 0. Then dimArray(atomicVar) + 1 would be executed, and if and only if the result was 1, could the process then continue.
Thoughts?
Is a threaded non-blocking circular buffer possible?
- RichAlgeni
- Addict

- Posts: 935
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: Is a threaded non-blocking circular buffer possible?
you should be able to do it with semaphores which only wait when they have to
Windows 11, Manjaro, Raspberry Pi OS


