[ntp:hackers] [Gpsd-dev] ntpd shm changes
Terje Mathisen
terje at tmsw.no
Sun Mar 20 10:00:17 UTC 2011
Dave Hart wrote:
> On Sat, Mar 19, 2011 at 11:20 UTC, Terje Mathisen<terje at tmsw.no> wrote:
>> The best you can do with a single producer and one/multiple readers (which
>> are allowed to read the same data), is probably to have multiple slots for
>> the data packets together with a single pointer to the current/last updated
>> slot.
>>
>> The pointer can even be a simple index, using a byte variable makes it
>> impossible for a reader to read a partially updated value.
>
> That sounds like a good way to go to me. Can you think of any reason
> two slots would not be enough? Also I'd feel better about the atomic
> handling of th index with it manipulated as the native word size
> (currently 32 or 64, could set aside 128 bits). At least on some RISC
> platforms, byte access is handled by the compiler as a native word
> size plus extra instructions, killing atomicity I believe.
Alpha was originally like that, but even that platform had atomic 32-bit
load/store ops.
For the really paranoid I'd allocate 64bits for each such variable, but
only store real data in the lower 32 bits, making it safe to use either
32- or 64-bit load/store ops.
Anyway, real atomic ops are much better, they just need
platform-specific code to handle it. :-(
Terje
--
- <Terje at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
More information about the hackers
mailing list