Condition Mutexes

dsimcha dsimcha at yahoo.com
Wed Oct 21 14:20:17 PDT 2009


== Quote from Bartosz Milewski (bartosz-nospam at relisoft.com)'s article
> dsimcha Wrote:
> > Bartosz, since you're a threading guru, could you please write a simple test
> > program using core.sync.condition and see if it works, and if not either file a
> > bug report or let me know?
> Conditions were implemented by Sean Kelly, so he's the guru. The file
condition.d in core.sync has unit tests, which presumably still run (although I
don't know if anybody still runs unit tests in druntime).
> If using conditions in D is harder than in Java, than we should rethink their
implementation. Every D object has a built-in mutex. Conditon variables should be
able to work with this mutex and with synchronized sections out of the box. The
most common case should be the easiest. The fact that you are having all those
technical problems proves my point.
> As for non-technical problems, rewrite your test so that you wait on a condition
in main and let the new thread do the signalling. That way they won't be able to
miss each other, as they currently do.

I got my test program to work and understand what I did wrong.  I think the real
problem is that:

1.  core.sync isn't even in the Phobos/druntime docs yet, and is still kind of
"here be dragons", so I originally thought it might legitimately just be broken.
2.  The docs for core.sync.condition assume you already know what a condition
variable is and how to use one and just provide a terse description of the
interface to the druntime implementation with zero examples.  On the other hand,
the details of this primitive are somewhat arcane and hard to find.  I'd vote for
improving these and will do it myself if noone else does it by the time I get some
higher priority hacking done.



More information about the Digitalmars-d mailing list