Re: [boost] Re: [Threads] Simple active object wrapper, take 2
by Mark Blewett other posts by this author
Feb 28 2004 1:08PM messages near this date
Re: [boost] FC++: formal review
|
[boost] Re: [Threads] Simple active object wrapper, take 2
At 01:02 28/02/2004, you wrote:
> scott <scottw <at> qbik.com> writes:
> > ps:
> > the sample code from mark blewett looks very promising?
> >
>
> Yes. Although from my point of view, it has the same drawback with switching
> on messages that you have. I wonder if the queue of messages in the servant
> class could be a queue of fully-bound function calls,
I'm halfway there, in that the queue holds callbacks, eg in
Servant::dispatch the "do something with m" simply executes the callback.
To give a usage example
class MyServant : public Servant
{
public:
MyServant(Scheduler* scheduler) : Servant(scheduler) {}
void do_fn(int x, int y) { std::cout << x << " " << y << std::endl; }
};
int main()
{
Scheduler scheduler;
scheduler.start(1,1);
MyServant my_servant(&scheduler);
my_servant.post_call(new
CallbackVAA<MyServant,int,int> (&my_servant, &MyServant::do_fn, 1, 2));
scheduler.stop();
return 0;
}
will result in the output "1 2" via one of the schedulers worker threads
> generated by proxy
> objects which describe interfaces? (Yes, I am quite enamoured of that
> idea :))
Interesting idea... assuming I'm understanding correctly.. in that the
callback is created by an object in the servant class, the above becomes;
class MyServant : public Servant
{
public:
MyServant(Scheduler* scheduler) : Servant(scheduler), fn(this,
&MyServant::do_fn) {}
MethodProxy<MyServant, int, int> fn;
private:
void do_fn(int x, int y) { std::cout << x << " " << y << std::endl; }
};
int main()
{
Scheduler scheduler;
scheduler.start(1,1);
MyServant my_servant(&scheduler);
my_servant.fn(1, 2); // certainly a lot easier to understand
than previous example!
scheduler.stop();
return 0;
}
Regards
Mark
Attachments:
unknown1
unknown2
Thread:
Mark Blewett
Matthew Vogt
Matthew Vogt
scott
|