[dmd-concurrency] Shutdown protocol

Robert Jacques sandford at jhu.edu
Wed Jan 20 12:12:06 PST 2010


On Wed, 20 Jan 2010 14:24:34 -0500, Michel Fortin  
<michel.fortin at michelf.com> wrote:
> Consider this case with a Dispatcher and a Worker thread communicating  
> with each other like this:
>
> Request:  Clients -> Dispatcher Thread -> Worker Thread
> Response: Clients <- Dispatcher Thread <- Worker Thread
>
> Clients send requests to a dispatcher thread. Dispatcher decides to  
> which worker to give the request. Worker does its work, sends the  
> response to the dispatcher, which sends it back to the client. Here the  
> dispatcher is in an infinite loop waiting for client requests, the  
> worker thread is in an infinite loop waiting for requests from the  
> dispatcher, and both know each other. Here you have your circular  
> reference.
>
> Is this a logic bug? I don't think so.
>
> It's true that you don't want those two threads to shutdown by  
> themselves in this case, but I'm a little uneasy about this being a  
> "feature" of reference counting.

Good example, but not really circular. Well, so long as the worker threads  
don't cache the dispatcher's tid. Assuming they don't, once the number of  
clients goes to zero and the number of workers doing work goes to zero,  
the ref count on the dispatcher goes to zero and it shuts down. Then the  
worker ref counts go to zero and they shutdown.


More information about the dmd-concurrency mailing list