[dmd-concurrency] Sending mesages to non-listening threads

Sean Kelly sean at invisibleduck.org
Tue Jan 12 12:11:48 PST 2010


On Jan 12, 2010, at 11:58 AM, Michel Fortin wrote:

> It's nice that you can now send messages to any thread like this:
> 
> 	tid.send(i);
> 
> But... what if you're sending a message to the wrong thread, to a thread that isn't listening for messages? Do the messages accumulate in memory until no memory is left? If that's the case, sending messages to the wrong thread would become a memory leak. Any solution?

Every thread created with spawn() will have a message queue, so in effect they're all listening.  If the user is sending messages to a thread and never processing them then it's a flaw in the program design.  About the only thing we could do about it is set a (possibly optional) max queue size and start returning "failure" messages once this limit is reached.  The drawback being that sending such automatic messages could screw up any protocol the user has in place.  I'd personally prefer to just leave this as-is, since the API is behaving in a logical and consistent manner.

There are a bunch of things still missing from the current API that will need to be addressed at some point though, like linking threads (so one will be notified if the other exits), a Tid registery, and probably a bunch of other things I'm forgetting offhand.  These aren't necessary for a first cut, but they'll have to be added soon after.


More information about the dmd-concurrency mailing list