ref. to object functions from threads
hi all, is there a way to get a reference to the function object used by a boost::thread object?? when you create a new thread and feed it a function object it copies it and then starts a new thread of execution on this object.. well, I would like to send messages to the object in which the thread is running but I don't know how to do it with boos.threads... is there a way to tell boost:thread not to copy the function object but to use it directly?, or to ask the thread object to give a reference to the object? I am now doing a dirty hack which consists of the object putting itself (a pointer) in a static chained list during construction and remove itself in the destructor, this way I can call a static member function which returns this list to get a hold of the object. There is also a static mutex protecting this list to make sure no other objects are created / destructed while one of them is inserting or removing itself from the list. it is working, but I don't think this is a very "clean" approach.. does anyone have any ideas how it could be done better?? thank you. regards, luis.
--- In Boost-Users@y..., Luis De la Parra
hi all, is there a way to get a reference to the function object used by a boost::thread object??
No, and it would be very difficult to do so, since the type is lost.
when you create a new thread and feed it a function object it copies it and then starts a new thread of execution on this object.. well, I would like to send messages to the object in which the thread is running but I don't know how to do it with boos.threads...
Only by wrapping it in an adapter. The boost::ref class is a very
good candidate for this. Here's an example, and I'll add this to
the next release:
#include
El Thu, 5 Sep 2002 23:34:39 +0200
Luis De la Parra
hi all, is there a way to get a reference to the function object used by a boost::thread object?? when you create a new thread and feed it a function object it copies it and then starts a new thread of execution on this object.. well, I would like to send messages to the object in which the thread is running but I don't know how to do it with boos.threads...
I use the pimpl idiom with a boost::shared_ptr<> doing the trick.
It's not very clean, but here goes my example:
---------------------------------------------------------
#include
participants (3)
-
bill_kempf
-
Luis De la Parra
-
Raul Huertas Diaz