In article <local.mail.freebsd-current/[EMAIL PROTECTED]> you
write:
>* Allen Pulsifer <[EMAIL PROTECTED]> [000329 21:05] wrote:
>> Here's another alternative for reading structures like time
>> that always change monotonically: read the values in
>> "MSB" to "LSB" order, then go back and check in reverse
>> order that nothing has changed. For example, to read a
>> structure containing hours, minutes, seconds:
>>
>> for (;;)
>> { h = timep->hour;
>> m = timep->minute;
>> s = timep->second;
>> if (m != timep->minute) continue;
>> if (h != timep->hour) continue;
>> break;
>> }
>>
>> The assumption is that from the instant you first read
>> timep->hour until the instant you double check its value,
>> it could not have wrapped all the way back around to its
>> previous value. Or to put it another way, if it has
>> succeeding in wrapping all the way around, having a
>> correct snapshot of the structure is the least of your
>> problems and the value you use is arbitary.
>>
>> This same method can be used to read the MSW and LSW of
>> any counter-like structure that is updated by an interrupt.
>>
>> Note this method will not work for a structure that can
>> both increment and decrement--it has to be only one or
>> the other.
>
>I'm aware of this, the problem is that tz may move in either
>direction. Hence my question about using sizes that are machine
>atomic for read/write. :)
>
>I've got several books on various systems here and I don't remeber
>any of them mentioning a problem with 32bit aligned updates being
>atomic.
Each architecture will define what is atomic or not. Most modern
architectures will provide atomic access to their native word size,
provided it is aligned on a natural word boundary.
On the PPro and upwards, 64 bit reads/writes to quadword aligned
structures are atomic. it's just too bad that there is no direct
64-bit read insn (excluding FP).
--
Jonathan
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message