
I'm thinking of the same thing, and would reach for std::tr1::function generalized function objects to be the callback object queued between threads. between 'function' and 'bind', both standard now, it should do the trick. This will play nicely with compiler-native lambdas when they are available to your project, too. From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Steve Lorimer Sent: Wednesday, June 02, 2010 4:36 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [bind] & [function] How do I store member functions with generalised arguments for later invocation? Thanks Nat, I didn't know about this yet (noob!)
From a quick perusal (almost bed time :) !) I can't see how I would achieve my aim, which is:
1. create the "event" (signal) which is associated with a member function "callback" (slot). Associate a thread with the event
(can I create a signal connected to a slot which is a member function?)
2. in any other thread, call "post" (sig(data)) where data is a shared_ptr
3. the callback (slot) is called, running in the context of the *other* thread (the one originally associated with the "event" / (slot).
I'm trying to encapsulate a generic inter-thread messaging system where objects are passed around between threads, and associated with a member function which is designed to process said objects.
This design is essentially a messaging system between threads - for a simple example - we have a producer/consumer thread model. The consumer thread is encapsulated in a class (eg: class consumer_thread), which has a member function (eg: void consume(struct data)). The producer creates an "event" object which is associated with the consumer_thread object, it's void consume(struct data) member function, and the thread which must process the data (consumer_thread). Now when the producer produces some data, it calls event->post(data), which queues up an object which records the class instance and it's member function which must be called with parameter "data", and a shared_ptr to data. The consumer thread wakes up, gets the top of the queue, and calls obj->mem_fun(data) --> ergo, mem_fun is called in the correct thread context, and has the argument "data" to consume.
Does that make any sense? I don't think I'm explaining it well. Any suggestions, (how to do what I'm asking for, or trashing my design and offering a better design), would be greatly appreciated!
TIA
Steve
On 2 June 2010 19:06, Nat Goodspeed