Looking for a lock-free RT-safe single-reader single-writer structure
Posted
by moala
on Stack Overflow
See other posts from Stack Overflow
or by moala
Published on 2010-02-25T15:07:30Z
Indexed on
2010/04/14
19:23 UTC
Read the original article
Hit count: 544
Hi, I'm looking for a lock-free design conforming to these requisites:
- a single writer writes into a structure and a single reader reads from this structure (this structure exists already and is safe for simultaneous read/write)
- but at some time, the structure needs to be changed by the writer, which then initialises, switches and writes into a new structure (of the same type but with new content)
- and at the next time the reader reads, it switches to this new structure (if the writer multiply switches to a new lock-free structure, the reader discards these structures, ignoring their data).
- The structures must be reused, i.e. no heap memory allocation/free is allowed during write/read/switch operation, for RT purposes.
I have currently implemented a ringbuffer containing multiple instances of these structures; but this implementation suffers from the fact that when the writer has used all the structures present in the ringbuffer, there is no more place to change from structure... But the rest of the ringbuffer contains some data which don't have to be read by the reader but can't be re-used by the writer. As a consequence, the ringbuffer does not fit this purpose.
Any idea (name or pseudo-implementation) of a lock-free design? Thanks for having considered this problem.
© Stack Overflow or respective owner