[ntp:hackers] [Gpsd-dev] A lightweight synchronization mechanism for shared memory
terje at tmsw.no
Fri Mar 25 09:48:58 UTC 2011
Håkan Johansson wrote:
>>> If the writer crashes in a mid-update, say entry 3, then until the next
>>> alive writer has overwritten that entry, say when it just claims to be
>>> writing next entry 4, the reader may get the idea that the previous
>>> entry (number 3) is now good and usable.
>> I did state up front that my approach is specifically designed for a
>> single writer with one or more readers: If the writer crashes then you
>> obviously get no more valid updates! :-)
> Sure, but if another writer then comes online, is it possible for the
> reader to be fooled to read and use some old inconsistent data?
OK, so either a restart of gpsd or another source?
That would be perfectly OK, the new (single) writer would simply
overwrite the next (partially updated) entry, then finally get around to
updating the counter.
unsigned cnt = shm->count + 1;
cnt &= shm->count_mask;
... write the new record to entry [cnt]
Multiple writers otoh breaks it all!
- <Terje at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
More information about the hackers