[pdg-group] Meeting

Xiong Ming ming.xiong at vanderbilt.edu
Sat Mar 20 21:41:27 CST 2004


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

Don Hinton wrote:

>Hi Ming:
>
>On Fri, 19 Mar 2004, Ming Xiong wrote:
>
>  
>
>>Hi, guys:
>>    I know that one object associates one thread of control, so that if
>>client makes a call to scheduler invoking its insert () method, the
>>scheduler event-loop will stop for a while to handle that request. But
>>what if the method that the event-loop run under is a static method,
>>which can exist without having to instantiate the object? Like in the
>>paper, when we use Thread_Manager to spawn a thread for the scheduler,
>>it actually spawns a thread for a static method of the scheduler, why do
>>we have to define the method static? It has to be a reason. Maybe I'm
>>missing some concurrent programming principle here? Do you have any
>>idea?
>>    
>>
>
>To spawn a thread, you have to pass the address of the function you want
>to run.  Typically, that will be something like this:
>
>void* foo (void*);  // Unix
>DWORD foo (void*);  // Windows
>
>and in the article (page 381) MQ_Scheduler::svc_run uses this prototype, 
>i.e.:
>
>  static void *svc_run (void *arg);
>
>The reason it's static is that Thread_Manager::spawn requires an address
>of a C function to execute, and static functions meet that requirement,
>i.e., they use C linkage.  Non-static methods have C++ linkage and
>implicitly pass the pointer to the containing object as the first
>parameter, that's how you get "this."
>
>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?

sense that we need the scheduler object to insert  a new method request 
into the Activation List, which in turn will be used by dispatch ();
here comes a request,

> Therefore, each instance of
>MQ_Scheduler has only a single thread, the one created in the ctor, and
>that thread is running the dispatch method for that instance.  The Monitor
>pattern is used to protect the internal list, so although many threads can
>potentially add stuff to the list, only the thread created by the object
>itself is removing requests from the list and acting on them.
>
>hth...
>don
>
>  
>
>> 
>>Ming
>> 
>> 
>> 
>>-----Original Message-----
>>From: Abdullah Sowayan 
>>Sent: Tuesday, March 09, 2004 12:59 PM
>>To: pde-group
>>Subject: [pdg-group] Meeting
>> 
>>Hi everyone,
>> 
>>So we are not having meeting this Friday because it is spring break and
>>not a lot of people are around. 
>>We are having our meeting the first Friday after spring break. We will
>>discuss the "Active Object" pattern. You can find it at the following
>>link
>>\\ISIS-grad\USER\sowayaa\POSA2 <file:///\\ISIS-grad\USER\sowayaa\POSA2> 
>> 
>>If you can not access that folder, email me and I'll send it to you
>>directly.
>>
>>Take care,
>>Abdul
>>
>>    
>>
>
>
>
>  
>




More information about the pdg-group mailing list