ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved