[pdg-group] Meeting

Don Hinton dhinton at dre.vanderbilt.edu
Sun Mar 21 04:10:31 CST 2004


Hi Ming:

On Sat, 20 Mar 2004, Xiong Ming wrote:

> Hi, Don:
>     Thanks!  Your reply makes perfect sense to me. Would you mind if I 
> ask some further questions? I wouldn't let go the opporutnity to get
>  a little more in-depth on this issue, because you are soooo familiar 
> with this Active Object pattern, ;-). Please see below

You're welcome...

<snip>

> >Anyway, when MQ_Scheduler's ctor calls the Thread_Manager::spawn method,
> >it passes the address of the svc_run function, and "this," a pointer to
> >itself, as a void*.  svc_run, then dynamic_cast's void *arg back to a
> >MQ_Scheduler* and invokes dispach() on it. 
> >
> Yes, the dispatch () method basiclly runs a for loop (in a separate 
> thread) that continuely iterate the Activation list to see if a certain 
> method request
> is runnable. When the can_run () (or guard ()) of a method request 
> returns true,  it will execute the request via its actual servant 
> (MQ_Servant).
> 
> On the other hand,  the client thread uses MQ_Proxy to respond to 
> request. As we know, MQ_Proxy maintains a pointer scheduler_ that points 
> to the instance of the MQ_Scheduler, which is now running the dispatch 
> () in a separate thread.  When here comes a new request, e.g., get (), 
> the client thread will create a new method requst object and insert it 
> to the activation list by invoking scheduler_.enqueue (method_request). 
> Here comes a issue of concurrency. When we invoke scheduler_.enqueue (), 
> is it going to affect the running of dispatch (), considering the fact 
> that the two methods are running at the same time in separate threads 
> but are invoked on the same object?  Or a better question is, will the 
> scheduler_.enqueue () in the client thread make a contact with dispatch 
> () in the seperate thread to sort of let dispatch () stop for a while to 
> process scheduler_.enqueue ()? This is kind of complex, if i didn't make 
> myself clear enough, you can think of it  as a question like: Is it 
> possible for a object to process two methods simutaneously if the two 
> methods are running on different threads?

Access to the internal list or queue must be synchronized, but that's
sorta implicit in the design.  The book mentions this on page 383 but
doesn't go into detail.  I think Doug's suggestion of looking at chapter 6
in C++NPv2, the ACE_Task Framework (which implements the Active Object
Pattern), would be a good idea, since it goes into detail about how to do
this.  You can also just look at the ACE_Task implementation, i.e,
ACE_wrappers/ace/Task*.

If you don't have access to C++NPv1 and C++NPv2, you can borrow mine...

hth...
don



More information about the pdg-group mailing list