[Gllug] Programming: Atomic Increment/Decrement

Dave Cridland dave at cridland.net
Wed Aug 7 16:55:23 UTC 2002


On Wed, 2002-08-07 at 14:27, Jonathan Dye wrote:
> > isnt that what you use a mutex for?
> > 
> > pthread_mutex_init(3)
> 
> You _can_ use a mutex to protect the increment/decrement but it is usually
> quite heavyweight.  A mutex is good if you are doing more than a simple
> increment or decrement.

Are you essentially talking about a semaphore of some sort? I'm not
saying you are, mind, but often inc/dec atomicity problems can be done
with semaphores.

Unless you want them to go below 0, of course.

Dave.


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list