December 15, 2005
Hi!

I did some work on condition variables in GDC last week and I would like them to be included and tested "out there".

The patch is pretty simple, but targeted towards GDC. However, the only existing file it patches is phobos/internal/monitor.c, so it should fit into DMD quite easily.

A couple of remarks:

The code uses pthreads on POSIX and semaphores and critical sections on Windows.

There is a test thing implementing the Windows stuff in pthreads so
I could test the algorithm under Linux. I haven't actually tested it under
Windows.

I checked the pthread-w32 implementation of condvars, but I think they are doing things too complicated. Doing condvars using semaphores is a standard homework task in parallel programming, so it should be fairly simple (assuming Win32 semaphores work).

monitor.c has been patched so I could get hold of the synchronized()
mutex.

Documentation should be fairly complete (though not meant for people not accustomed with Hoar monitors)

You don't need to run signal() from within a synchronized() block.
This differs from Java, but I couldn't find any reason not to allow
this. Anyway, the first thing that happens in signal()/broadcast() is
to lock the mutex, so it would just be a matter of removing those
locks.

Both Windows critical sections and the current pthread mutices are
recursive, so the signal()/broadcast() issue above should allow them
to be run as normal (inside a monitor()).

Many regards,
Tommie Gannert
 - Just a fan