Boost logo

Boost :

From: Roland (roland.schwarz_at_[hidden])
Date: 2004-01-06 07:37:03


Hi Matthew,

I am glad to read your post.
I tried for several times to post a similar question than your
"how do I shut down an active object that is blocked waiting...",
but never got any response. Perhaps this time we can give
new momentum to the discussion?

(Matthew Hurd <matt_at_[hidden]>) wrote:

> To wait on two or more things _without_ polling, or timed blocking, you are
> going to have to encapsulate a wait for multiple objects like thing using a
> 1 to n thread technique where a thread blocks waiting for one of the other
> threads to notify my condition which will then cancel the other threads from
> waiting. However, this in turn will require the other threads to be
> cancelled, or timed block with their wake up and signalling to check if they
> should shut down. It is getting messy as this will require polling, or
> timed blocking, in the dependent threads as boost does not support thread
> cancellation.

I think that your suggestion, altough beeing a workable soulution, might be a bit
too general. Do you really think it is necessary to be able to wait for
arbitrary multiple objects? Waiting for multiple objects in Windows API is as
I can understand basically a different (but semantically related) concept to
beeing able to wait on a single condition, and then test the (lock protected) predicates.

>
> This is a similar question to a simpler question of how do I shut down an
> active object that is blocked waiting... Cancel the thread, timed block
> with shutdown condition check or wait for one of two signals. I can only
> see a solution with the second option within boost which is what I currently
> use for my message and priority queues.

It is interesting to see that you are thinking that these problems are equivalent.
I solved the first one (shuting down an object on which multiple threads are
blocked) entirely by building on top of the existing boost.thread API by writing
a cancelable_condition class that inherits from condition. This way I also was
able to write a cancelable_thread class, that is cancelable, as long as a
thread is blocked in a cond.wait(lk).

But I got stuck, because I cannot cancel the thread (or the object) when it is
blocked on IO. So solving the multiple wait problem would also solve the
cancellation problem. Or as you say the other way round solving cancellation
would solve the multiple wait (altough I am not yet convinced about this latter one).

>
> Anyone see a better option? Does posix provide a win32 WFMO equivalent
> boost can wrap?

All I know about is the select statement. But I do not know whether it is Linux specific.
Also I think it is only applyable to file descriptors.
But I think that there could be some common ground: Concentrating on file descriptors (posix)
and Filehandles (Win32) and not trying to move over completely to WFMO.

Regards,
Roland

BTW.: When I say "active object" I do not really speak about an object that has an embedded
thread. I am speaking about the "Thread-safe Passive Object" <Monitor Object, Douglas C. Schmidt>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk