DragonFly BSD
DragonFly users List (threaded) for 2005-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Blocking on multiple threads with timeout

From: Jonathon McKitrick <jcm@xxxxxxxxxxxxxxxxx>
Date: Mon, 28 Feb 2005 00:58:49 +0000

On Sun, Feb 27, 2005 at 06:00:01PM +1000, Andrew Hacking wrote:
: FYI: pthread_cond_timedwait() allows your waiting thread to block on a
: condition variable, which your other worker threads could signal when
: they have completed.  When your waiting thread awakes due to a timeout,

Ah, yes.  I'm still working my way through the man pages.  'Advanced Unix
Programming' doesn't cover that call, so I haven't gotten to it on my own
yet.  I'm still working my way through userland unix calls.

: WARNING: I have never used pthread_cancel() because its a nightmare to

I've been learning about the cleanup handlers, and I think I'm going to try
other ways to shut down threads instead.

: Instead, you may want to re-consider the software that *allows* your
: worker threads to block indefinitely, because it probably won't be

Well, on the first round, we check for the device we are talking to (serial,
GPIB, IP, USB, etc.).  That is where a timeout is most likely to occur.  But
this operation is performed serially, so no threads are spawned.  But after
that, we spawn threads to initialize each device (which is full of motors
and such) and this can take a minute or more.  Basically, I should be able
to write the init thread to timeout if the 'ok' reply has not been received
after the 'init' command has been sent to the device.  Is that what you are

: operations that can block indefinitely.  This is much easier and more
: reliable than the above high wire act, and often avoids the need for a
: "manager" thread altogether.

I'd like to start the init threads, put the id's in an array, block until
they are all done, then continue.  Each thread should have its own timeout
handling internally.

Jonathon McKitrick
My other computer is your Windows box.

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]