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

David Brown dlang at davidb.org
Sat Oct 6 22:33:29 PDT 2007


On Sun, Oct 07, 2007 at 07:07:09AM +0200, downs wrote:

>I think the problem is that people get so used to their favorite
>threading primitives that they  believe synchronization and multiple
>threads working together is entirely impossible without them.
>As somebody who has written multithreaded programs using exclusively D's
>and Phobos' threading primitives, let me assure you that it is very much
>possible :)

Not the case at all.  My original intent was to look into phobos and see
what primitives were available.  Phobos threads have 'synchronized' which
is part of the grammar of the language.  Apparently, windows has some
mechanisms that work well with this to provide the rest of the necessary
mechanisms.  The linux synchronization primitive does not work with the
D/Phobos 'synchronized' primitive, since the mutex used to make the lock is
not accessible.

In either case, there is no way to do a portable threading program, since
it requires access to other os-dependent features to do anything useful.

>With that in mind, I'd kindly ask you to describe some basic, common
>situation that you believe is outright impossible to do with Phobos'
>threading, because I honestly can't see any.

I'll give an inverse challenge (which I'm going to try and meet, see
below): Implement a standard threading problem, such as bounded buffers
using only the Phobos thread primitives.  The solution may not use anything
outside of std.thread for synchronization.

All completely threading interprocess coordination mechanisms are
functionally equivalent.  Ones that use shared memory (threads) boil down
to two things:

   1.  A way to provide exclusive access of a piece of memory.
   2.  A way for a thread to block and be awoken by another thread.

Phobos provides #1 through 'synchronized' and #2 possibly through
pause/resume on threads.  Windows provides other mechanisms for #2 that are
probably easier to use.  Linux provides condition variables that can't be
used with 'synchronized' blocks in D.

The rest becomes a matter of convenience, and how easy the mechanism is to
use correctly.

I'm going to take it as an exercise to implement the bounded buffer problem
in D using only std.thread and nothing else.  I will post the code here
when I am finished.

David



More information about the Digitalmars-d mailing list