Is there a way to use pthread_cond_timedwait() with semaphores? I would like to use regular POSIX or System V Semaphores, rather than simulate them using other synchronization objects. Should I decide to simulate them, I'll probably go with a raw assembly command like CMPXCHG (which would probably be more "atomically correct" for cases when the semaphore is incremented/decremented by more than 1). However, my impression was that using a test-and-set algorithm will require additional testing to determine how long to spin when the test-and-set fails.
After thinking about this some more, what I'd really like to do is to be able to send an asynchronous signal directly to the thread that is blocked in sem_wait(). Signaling a specific thread will also be useful for general thread-interruption purposes. Is there a way to do this using the thread id or something?
Main Topics
Browse All Topics





by: duncan_roePosted on 2006-12-10 at 22:30:58ID: 18113209
pthread_cond_timedwait() is a reasonably standard posix implementation of what you're seeking to achieve.
Under linux at least, a timer process can use the Real Time Clock - very accurate as you get told about missed interrupts.