[pdg-group] Meeting

Don Hinton dhinton at dre.vanderbilt.edu
Sat Mar 20 21:42:19 CST 2004


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.  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