gettimeofday seconds rollover problem?
Eric Norum
norume at aps.anl.gov
Fri Feb 24 19:34:03 UTC 2006
On Feb 24, 2006, at 1:09 PM, Till Straumann wrote:
>
> Not sure I understand exactly what you mean. Assume a (global)
> variable X
> that is not touched by an ISR. If some operation does
>
> _Thread_Disable_dispatch();
> X++;
> _Thread_Enable_dispatch();
>
> Then, for sure, X is not modified by any ISR. However, the compiler
> could
> still move X outside of the safe region (because the dispatch-
> disable/enable
> ops are inlines) so it effectively looks like this
>
> X++
> _Thread_Disable_dispatch();
> _Thread_Enable_dispatch();
>
> with obvious consequences if a context switch occurs while X++ is
> in progress.
Yes, and the "memory" barrier will prevent this which is why I agree
that it should be added to the _Thread_Disable_dispatch and
_Thread_Enable_dispatch macros/inlines.
Declaring X as volatile is orthogonal to the "memory" barrier issue.
If the X in the above example is used by multiple threads then it
needs to be volatile -- this is likely given the above example code,
but has nothing to do with the presence or absence of the memory
barriers.
If the X is used by only one thread then it does not need to be
volatile.
--
Eric Norum <norume at aps.anl.gov>
Advanced Photon Source
Argonne National Laboratory
(630) 252-4793
More information about the users
mailing list