Article View: comp.os.mach
Article #1291timeout on condition_wait()
From: Eric Hammond
Date: Fri, 16 Feb 1990 21:36
Date: Fri, 16 Feb 1990 21:36
52 lines
2754 bytes
2754 bytes
Suppose cthread T1 begins waiting on a condition C1.
The condition may be signalled by cthread S within n1 seconds,
but, if it isn't, I want cthread T1 to stop waiting and continue
processing. In other words:
===> I want to do a condition_wait() with a timeout. <===
[ The rest of this message gives further details about my
particular application. Any suggestions on how to do the above
are welcomed, even if the following doesn't make sense to you. ]
Complicate this by the fact that there may be m cthreads (and a
corresponding m conditions) all beginning their condition_wait()s
at different times and with different timeout lengths. In fact,
additional cthreads may be created at any time desiring this
ability.
Cthread S is the only cthread which signals any of the conditions,
and it does so based on different messages it receives from other
tasks. I can't easily do a msg_receive() in cthread S with a timeout.
One solution I have thought of is to create a set_timer() function
which keeps track of which cthread times out next and uses itimer
to call a handler function at that time. The handler function
would then signal the appropriate condition and then set the
itimer to wake it up again at the next appropriate time. There
would also be a clear_timer() function that could be called when
the condition was signaled by cthread S. However, this could quickly
get messy.
The other method I thought of (and the one I am currently using)
is for cthread Ti ("T-sub-i") to cthread_fork() a timer cthread
before doing the condition_wait(). Cthread Ti passes the timer
cthread the number of seconds and the condition (Ci) to signal
when the seconds pass. The timer cthread simply does a sleep() and
then signals the condition.
The problem I'm having with this second methond is as follows:
Cthread Ti receives a signal on condition Ci from cthread S while
the timer cthread is sleep()ing, and then wants to do another
condition_wait() on condition Ci with another timeout. The old timer
cthread must be stopped from signalling condition Ci. I had been
doing this with thread_terminate(cthread_thread(timer_cthread)) from
cthread Ti, but as Rich Draves pointed out this may be risky.
I would appreciate any suggestions or further questions by email
or news. Thanks!
--
Eric Hammond
erich@kgw2.bwi.wec.com
Technical Details
Message-ID:
<375@kgw2.bwi.WEC.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!uccba!spca6!kgw2!erichShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!uccba!spca6!kgw2!erich From: erich@kgw2.bwi.WEC.COM (Eric Hammond) Newsgroups: comp.os.mach Subject: timeout on condition_wait() Message-ID: <375@kgw2.bwi.WEC.COM> Date: 16 Feb 90 21:36:04 GMT Distribution: usa Organization: Xetron Corp, Cincinnati Ohio Lines: 52