[interfacekit] Re: BLocker's implementation issue(?)
- From: "Erik Jaesler" <erik@xxxxxxxxxxxxxx>
- To: interfacekit@xxxxxxxxxxxxx
- Date: Mon, 01 Sep 2003 08:13:36 -0700
Unless I'm horribly mistaken (and I'm sure I will be quickly corrected
if I am), this implementation is fine. oldBenaphoreCount is a stack
variable that is only going to exist in the thread it was created -- if
another thread is in this function, it will get its own instant of
oldBenaphoreCount. The danger is only that separate threads operating
on the same object will get into a race condition incrementing
fBenaphoreCount, which the atomic_count deals with nicely.
e
>I was looking through BLocker's source code, and I noticed this:
>
>int32 oldBenaphoreCount = atomic_add(&fBenaphoreCount, 1);
>if (oldBenaphoreCount > 0) {
> etc. etc.
>
>
>Should this be
>if (atomic_add(&fBenaphoreCount, 1))
> etc. etc. ?
>
>Since the value returned from atomic_add could change before executing
the if.
Necessity is the plea for every infringement of human freedom. It is the
argument of tyrants; it is the creed of slaves.
-William Pitt, British prime-minister (1759-1806)
Other related posts: