[dmd-concurrency] draft 5

Michel Fortin michel.fortin at michelf.com
Tue Jan 19 05:02:25 PST 2010


Le 2010-01-19 à 5:30, Andrei Alexandrescu a écrit :

> I uploaded draft 5 here:
> 
> www.erdani.com/d/fragment.preview.pdf

Extracts from it:

> As discussed, passing data around is possible because of immutable; if you replaced immutable(ubyte)[] with ubyte[], the call to send would not compile.


That's nice and appropriate for inter-thread communications.

But won't it be a little wasteful when we come to inter-process or network communications, when you need to make a serialized copy of the message? If you force the user to make an immutable copy, and then create a new copy via serialization, the immutable copy is wasted, no?

I ask now because this is a pretty fundamental thing (passing a message) and you said at the start of this mailing list that the intent was for the message API to scale well to all these cases.


> enum OnCrowding { block, throwException, ignore }

What's going to be the standard for naming things in Phobos? Walter's guideline says enum members and constants should be ALL_CAPS, but looking at your code Andrei, here and elsewhere in Phobos, it doesn't seem like you like this rule.

Also, "throwException"... wouldn't it be better if it was named so to tell us which kind of exception is thrown? Like "throwTooCrowded" or something. Which makes me think that I don't see anywhere in your text which kind of exception is supposed to be thrown.

Last is an idea to improve the API, but probably won't have any consequence on the book unless you want to talk about it. In addition to the function taking standard enumerated values I think having this would be great:

	alias void delegate(Variant message) shared OnCrowdingHandler;
	void setMaxMailboxSize(Tid tid, size_t messages, OnCrowdingHandler doThis);

With this I could setup things so that if one thread is crowded the message would be sent to another thread instead. I could also want to write a log of those unpassed messages or something. Or I could make a zero-sized mailbox and use the crowding callback to send the message using an alternate dispatching mechanism (like sending a GUI event, making the GUI tread able to receive messages).

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list