Proposal: adding condition variable to object monitors

Jeremie Pelletier jeremiep at gmail.com
Sat Mar 14 23:50:30 PDT 2009


I would like to propose the addition of condition variables to the language, or at least to the standard library. They complement the current monitor's mutex very well, are only allocated when needed and can even be part of the base Object class.

I've included the basic implementation i currently use on the language runtime I am working on in my spare time (which is a fork of phobos from about a year ago). It supports vista and posix so far, although I didn't test the posix one yet.

The included file also contains a working unittest with sample usage.

Here is what I added to my Object declaration for even more convenience:
---
abstract class Object {
	// [...]

	synchronized void Wait(uint interval = -1) {
		(cast(Monitor*)this.__monitor).Wait(interval);
	}
	synchronized void Notify() {
		(cast(Monitor*)this.__monitor).Notify();
	}
	synchronized void NotifyAll() {
		(cast(Monitor*)this.__monitor).NotifyAll();
	}
}

private import dlib.Monitor;
---

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Monitor.d
Type: application/octet-stream
Size: 6351 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20090315/a094fa11/attachment.obj>


More information about the Digitalmars-d mailing list