Boost logo

Boost :

From: Preston A. Elder (prez_at_[hidden])
Date: 2007-11-13 22:22:29


On Wed, 14 Nov 2007 01:44:46 +0000, Preston A. Elder wrote:

> On Tue, 13 Nov 2007 19:50:04 +0000, Preston A. Elder wrote:
>
>> Ironically, the new interface makes this whole thing harder. Mainly
>> because of two reasons:
>
> OK, I take it all back!
>
> Here is my new interruptable_mutex, using the new boost::thread:
> http://www.neuromancy.net/fisheye/browse/mantra/trunk/Mantra-I/mantra/
utils/interruptable_mutex.h?r=428
>
> It turns out it is much simpler to implement ;)

Seems I spoke too soon, again ;)

I am having one difficulty - though not with anything already implemented.

The way I used interruptable_pred is as such. I have a message that
passes through various tasks. Inside each task (which for the sake of
argument, is a function), they create an interruptable_pred and associate
it with the interruptable_mutex for that task. Then they 'give' the
interruptable_pred to the message while they want the message to be
interruptable. Once they are no longer interruptable, they removed it
from the message.

This way, I could, from another thread do message->interrupt() and it
would check to see if it had a pred, and if so, call the interrupt
function on that pred which would then interrupt the other thread. This
then enabled me to also to call a function call instead of throwing an
exception (a minor detail, and not important at this point).

The new interruption syntax promises to make this even easier - for all I
have to do is now store the thread pointer in the message when
interruptable, and then when I call message->interrupt() it calls
thread->interrupt() and has the same effect as the interruptable_pred.

The problem is, the tasks need to be able to give the CORRECT thread
pointer to the message. But they can't. Because they did not create the
thread, they don't have the thread *, and all I can really do from within
a thread is call this_thread::get_id() - which, while useful, does not
help in this circumstance.

I can probably work around this whole mess (maybe using a thread-specific
pointer to store the thread pointer, since I do have control over who
DOES spawn the thread, this IS possible, however annoying ;P). But the
fact a thread cannot more or less look up its own thread for the purpose
of telling another thread "If you want to interrupt me, use THIS handle"
makes writing this kind of functionality difficult, and if I did not have
control over who creates the threads - impossible.

So, is it possible to get this fixed? :)

PreZ :)


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