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

Steve Schveighoffer schveiguy at yahoo.com
Tue Jan 12 12:12:29 PST 2010


----- Original Message ----

> From: Michel Fortin <michel.fortin at michelf.com>
> 
> 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?

Maybe a thread who doesn't want messages can close his incoming message handle?  Similar to a disconnected socket, the sender will get an exception or something (and trying to receive a message in such a thread would get an exception).

The other possibility is to only allow so many messages to be queued before the queue is "full".  Unsure what you want to do at that point though, either block or return an EAGAIN type error (maybe you can do both depending on how you want to send the message).  This solution is at least more likely to show logic errors, since with the first solution you may forget to close the handle.  But it also could cause deadlocks or force you to write handling code for full queue conditions.

How does erlang handle this?

-Steve



      


More information about the dmd-concurrency mailing list