I want to synchronize two threads. At the moment i am using double rotating dirty buffers that swap with a lock.
However it occurred to me i am only doing this to prevent dirty data from a write happening at the same time as a read. Can i store a flag in the most significant bit to convey data? or can i even go as far as whole byte.
For instance i can have an array of these and convey a lot of information in the form of bools. Reading and Writing is thread safe because the hardware can not read and write a single bit at the same time. So no garbage data.
Is this feasible? Is this the whole notion of atomic types.
Yes I think that could work, when testing your flags you would want to do an atomic test and set or compare and swap operation to set the flag indicating a write was occuring. You would need to make sure you the appropriate keyword in your language (e.g. volatile or atomic possibly), or use some OS provided compare and swap functionality. Have a look at this for a good example:
http://drdobbs.com/embedded-systems/210604448?pgno=1