knowledge-database (beta)

Current group: comp.arch

Re: POSIX/pthreads question

Re: POSIX/pthreads question  
Alexander Terekhov
From:Alexander Terekhov
Subject:Re: POSIX/pthreads question
Date:Wed, 05 Jan 2005 04:42:53 GMT

Greg Law wrote:
>
> Hi,
>
> Apologies since this is slightly off-topic, but I decided this group was
> where I was most likely to get a knowledgeable answer!

c.p.t. is the right place. Followup-to set.

[...]
> Anyway, what I don't understand is how the mutex is reacquired once the
> timeout has expired, without running the risk that the calling threads
> blocks for longer, possibly forever.

With or without "wait morphing", unblocked (in sense of consuming
a signal [note that timedout thread may still consume a signal) or
thread cancellation request) threads contends with other threads
for mutex ownership without timeout. There's no guarantee that
they won't block forever. Timeout on cv.wait doesn't affect mutex
re-acquisition.

"The pthread_cond_timedwait() function shall be equivalent to
pthread_cond_wait(), except that an error is returned if the
absolute time specified by abstime passes (that is, [...])
before the condition cond is signaled or broadcasted, or if the
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
absolute time specified by abstime has already been passed at
the time of the call."

"When such timeouts occur, pthread_cond_timedwait() shall
nonetheless release and re-acquire the mutex"

IOW, you can block forever on a mutex even if you specify
'epoc zero' for cv.timedwait.

regards,
alexander.
   

Copyright © 2006 knowledge-database   -   All rights reserved