Subj : Tjme out in lock To : comp.programming.threads From : Alex Date : Wed Apr 06 2005 05:15 pm Hi, continuing with my learning about this (thanks everybody for the great answers) I was wondering if is possible to add time supportfor a semaphore (in user code). To be more explicit, if I have a simple semaphore that supports basic P V ops, is it possible to add a time_out? Ithought something like this (acquire for at most n secs) Enter critical section if sem is not acquired acquire else wait(n secs) if sem is not acquired acquire else TIMEOUT Exit critical section This seems to work, but I see a problem that entering the critical section creates a bottleneck if other threads try to enter the code. Ideally all threads should do the waiting concurrently, and then try to get the semaphore, but I'm not sure is possible? And one other problem is that if the semaphore is released while waiting, the thread will be waiting till the end of the timeout. Maybe a signal should be added or maybe do busy wait? Keep in mind I do this to learn. I know there already is support in pthreads, but I'm trying to understand and see it for myself. Thanks for any comment! .