[dmd-concurrency] priority messages
Michel Fortin
michel.fortin at michelf.com
Mon Jan 25 12:25:49 PST 2010
Le 2010-01-25 à 12:35, Andrei Alexandrescu a écrit :
> Michel Fortin wrote:
>> tid.send({ throw new Exception(); });
>
> I think this is a very interesting idea to consider, thanks Michel. Passing a function from one thread to another could simply mean "call this function instead of blocking in receive()".
The idea comes from libdispatch. Combined with Apple's block extension to C, you can do pretty much the same with it:
int global;
void func() {
dispatch_async(dispatch_get_main_queue(), ^{ global = 10; });
}
This example shows how to update a global variable always in the main thread, avoiding the need for synchronization. The main thread event loop will execute the block upon reception. It's pretty much the same really.
I think another idea worth taking from libdispatch is the concurrent queues. Although I wonder how efficient they might be without kernel support.
> That function in particular has signature void(), so it does not need to be shared.
A function pointer never needs to be shared, whatever its signature. The only thing it points to is code, and code is always immutable. The thread-local arguments you pass to it at the call site are guarantied to stay thread-local even if the function pointer comes from another thread.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the dmd-concurrency
mailing list