[ntp:hackers] [Gpsd-dev] A lightweight synchronization mechanism for shared memory
mikes at flatsurface.com
Fri Mar 25 12:53:47 UTC 2011
If I understand the problem being discussed, it is to provide a method
for a single (multiple preferred) writer to be able to update a data
structure, so that multiple readers can always identify whether they
have read invalid data, as might occur when they read while an update
This may be a solution, which allows for multiple writers and readers,
and I believe meets all the conditions:
1) Two copies of the data structure are kept.
2) Writers always update the second copy first, then the first copy.
3) Readers always read the first copy first, then the second copy.
4) Readers must compare both copies, if they differ, the data is
If some multiprocessor/optimizing compiler issue won't allow a complete
update/read of one data structure prior the update/read of the other,
it breaks. I'm sure there's a word for this property, but don't know
what it is.
There may also be a very improbable case where two writers can produce
invalid data as seen by reader, but it would require that one
"overtake" the other in exactly the same manner while updating both
More information about the hackers