[dmd-concurrency] Shutdown protocol

Robert Jacques sandford at jhu.edu
Wed Jan 20 10:59:32 PST 2010


On Wed, 20 Jan 2010 13:40:47 -0500, Michel Fortin  
<michel.fortin at michelf.com> wrote:
> Le 2010-01-20 à 12:40, Robert Jacques a écrit :
>
>> I like the updated example, but the updated shutdown protocol sounds  
>> like a race waiting to happen. For example, suppose you spawn a thread  
>> (A) and send it's tid to another thread (B) and then exit. The spawned  
>> thread dies and the other then runs into errors. So now B's racing on  
>> A's shutdown event and may have intended behavior one day and then  
>> throw a bunch of shutdown exceptions the next.
>
> Indeed. That's a bad thing about it.
>
>
>> However, expanding on this concept, if tid was ref-counted, shutdown  
>> exceptions could be thrown correctly and at least the above race would  
>> be avoided.
>
> Although with reference counting two or more threads referencing each  
> other would create circular references and never shutdown. In some cases  
> perhaps that's what you want though, if you use another shutdown  
> mechanism for instance, but you probably don't want this be implicit  
> when creating circular references.

I thought about that, but I couldn't actually come up with a real and  
still pathological circular construct: unlike with garbage, a thread  
normally self-terminates. So cycles end up being naturally broken. The  
only time you'd end up with a true circular reference situation is two  
threads sending and receiving from each other inside infinite loops. Which  
I'd define as a logic bug and an uncommon situation. You could always add  
manual shutdown calls, to handle these situations.



More information about the dmd-concurrency mailing list