DMD 1.022 and 2.005 releases - what's wrong with threading?

David Brown dlang at davidb.org
Sun Oct 7 10:41:18 PDT 2007


On Sun, Oct 07, 2007 at 09:50:09AM -0700, Sean Kelly wrote:

>> I mean, it's threads .. you can start them, halt them, run stuff in them
>> ... what more is needed? It's a very basic implementation, very close to
>> the OS; but thanks to synchronized, I generally found it easy to add the
>> primitives I needed.
>> Somebody kindly explain. Thanks.
>
> There are at least two known deadlock issues with the Phobos thread module. 
>  One I've suggested a fix for (it's related to how object finalization 
> occurs) and the other I've been unable to find the cause of.  The remaining 
> issues are more subtle and probably not a concern for the average user.  
> Thread.getThis is an O(N) operation when it could be O(1), etc.

I have several issues with it:

   - 'pause/resume' is not a useful thread primitive.  As we've seen by
     sample code, just doing simple things is dreadfully difficult, and very
     easy to get wrong, having deadlocks, starvation, and other issues.

   - 'pause/resume' aren't very efficient ways to implement synchronization,
     at least not on Linux.  If this is the mechanism that Windows gives for
     synchronization (which at least no longer is the case), something else
     needs to be implemented on top of it.

     On Linux, pause/resume are far from "close to the OS".

     Even on windows, it seems unlikely to me that the only threading
     primitives provided require the user to implement their own wait queues
     and require waking every waiting thread to prevent deadlocks.

As I've said before, Phobos should contains a small set of easy to use
primitives that are efficiently implemented on the underlying OS.  This is
not currently the case.

As nearly everyone who develops threading primitives discovers, essential
to making them work is the importance of something that will block while a
mutex is held, and does the right thing.  This gets rid of most of the
loops and races that occur without this.

Aside from that, it would be useful to have a set of higher-level
synchronization operations, such as bounded and unbounded buffers,
implemented on top of this that are also part of a common library.

David



More information about the Digitalmars-d mailing list