Boost logo

Boost :

From: Preston A. Elder (prez_at_[hidden])
Date: 2008-08-26 10:49:50

I want to be able to get an interruption callback (as, say a
boost::function) for the current thread.

Here is the deal - I have a boost::thread_group, now each thread is
creating a series of messages. This message passed from thread to
thread, and as it passes to a new thread, each thread needs to put into
the message a callback function that can be used to interrupt the thread
that owns said message. This is mainly so that if I want to do something
with the message mid-'flight' (the request will come from a different
thread processing the message), and it happens to be waiting on a
condition, I can interrupt that thread and handle the change request on
the message.

Here is the problem - there is no way to get the callback function from
within the thread itself, or indeed. The best I can do is create the
thread then set the function in some kind of data structure AFTER the
thread has been created, and use some kind of condition or something to
'hold' the new thread until this function has been set. This is kind of
dodgy imho. It also requires me to keep a secondary structure pretaining
to a thread outside the thread_group. At which point I may as well do
the thread_group by hand (which, given the simplicity of thread_group is
not a huge amount of code, but still).

So, is there a solution that will satisfy the code poet in me? or do I
just roll my own thread group?

PreZ :)

Boost list run by bdawes at, gregod at, cpdaniel at, john at