[parisc-linux] atomic_t

John Marvin jsm@udlkern.fc.hp.com
Sun, 13 Jan 2002 23:54:21 -0700 (MST)


> >
> > But someone thought it was time to reset the counter. And if
> > it "never happened", then whoever is looking for 'v == 1' will
> > never see it.
>
> It's a race though; they can't guarantee to see it anyway.
>

Yes, it is a race in that you can't be guaranteed that you will ever see
the value equal to 1. But you should be guaranteed that it WAS reset.

For example:

    1) Initialize counter to 1.
    2) Increment counter by 1 each time event "X" occurs using
       atomic_add_return.
    3) Reset counter to 1 each time event "Y" occurs using atomic_set.
    4) Signal an error if the counter ever exceeds some threshold
       value, i.e. it is an error if too many "X" events occur without
       and intervening "Y" event.

In the above scenario you could not be guaranteed that you would ever see
the counter at one (or any particular value), but you could falsely
trigger the error condition if the resets were lost (by removing the
spinlocks from atomic_set).

John