Go to the FreeLists Home Page Home Signup Help Login
 



Browse interfacekit: This Month's ArchiveMain Archive PageRelated postsPrevious by DateNext by Date

[interfacekit] Re: BLocker's implementation issue(?)

  • From: "Axel Dörfler" <axeld@xxxxxxxxxxxxxxxx>
  • To: interfacekit@xxxxxxxxxxxxx
  • Date: Mon, 01 Sep 2003 17:06:10 +0200 CEST
"burton666@xxxxxxxxx" <burton666@xxxxxxxxx> wrote:
> 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.

No no, atomic_add() returns the old value of fBenaphoreCount and at the 
same time, atomically sets it to another value (adds one).
The "oldBenaphoreCount" variable won't be changed anymore - it reflects 
the state at the time atomic_add() was executed, and we are only 
interested in that state (if it has changed in the meantime, the other 
thread will block, but we don't have to).

Adios...
   Axel.


Other related posts:

  • [interfacekit] BLocker's implementation issue(?)
  • [interfacekit] Re: BLocker's implementation issue(?)
  • [interfacekit] Re: BLocker's implementation issue(?)




  • [ Home | Signup | Help | Login | Archives | Lists ]

    All trademarks and copyrights within the FreeLists archives are owned by their respective owners.
    Everything else ©2008 Avenir Technologies, LLC.