Subj : Two semaphore questions To : comp.programming.threads From : Ian Pilcher Date : Sat Mar 05 2005 10:02 am Two newbie questions about (realtime) semaphores: 1. I initially wanted to use a semaphore as the reference counter for a object shared by multiple threads, which seems to be the intended use. The last thread to dereference the object must free it, how- ever, and I believe that this requires a method of atomically decrementing the semaphore and retrieving its value, something which doesn't seem to exist. Have I missed something? (I've fallen back to using a mutex- protected int.) 2. Sort of the reverse of #1. I'm currently using a mutex-protected int as the global exit flag in my application. From an API point of view, a semaphore looks simpler -- sem_post to set the flag and sem_getvalue to check it. Other than the need to initialize the semaphore, is there a reason not to use the semaphore? Thanks! -- ======================================================================== Ian Pilcher i.pilcher@comcast.net ======================================================================== .