www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Revamped concurrency API

reply Sean Kelly <sean invisibleduck.org> writes:
MIURA Masahiro Wrote:

 Jeremie Pelletier wrote:
 I also don't believe one model is "ruling them all".

Let me clarity this, just in case I have caused an unnecessary confusion: I think Sean's Erlang-like API is meant to coexist with the current core.thread, and that you can use one or both of them to build higher-level concurrency models.

Exactly. That's also why I settled on the Erlang-like API instead of something like coroutines. It's possible to build a coroutine API on top of the Erlang API, but not vice-versa.
 I think it's nice to have core.thread *and* message-passing API
 in Phobos.  Thread alone is too primitive for daily use, but
 we don't want to have too many concurrency models.

I see core as holding language-essential stuff and "close to the metal" APIs, and have no inclination of hiding core.thread or core.sync from the user. If someone wants to work at this level and they understand the risks they should be able to. Any higher-level stuff like the message-passing API I proposed would live in Phobos and sit on top of what's in core. I disagree about poor performance though. With unique references or move semantics, a copy of even complex data isn't necessary to ensure that a message is passed safely.
Oct 13 2009
parent reply Michel Fortin <michel.fortin michelf.com> writes:
On 2009-10-13 11:39:21 -0400, Sean Kelly <sean invisibleduck.org> said:

 I disagree about poor performance though.  With unique references or 
 move semantics, a copy of even complex data isn't necessary to ensure 
 that a message is passed safely.

Yeah, but for unique reference to be usable you need lent semantics, otherwise you can't make sure you're the unique holder once you call a function to do something with your unique object. Anything that use the reference could be storing it elsewhere: unique!Object o = new Object; o.doSomething(); How in the example above can I enforce that doSomething() won't escape the 'o' reference elsewhere? 'doSomething' could be made 'pure', but that trick will only work for one-argument functions (in the case above, the argument is the implicit 'this') because otherwise a pure function could leak the reference through another argument. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Oct 13 2009
parent Sean Kelly <sean invisibleduck.org> writes:
Michel Fortin Wrote:

 On 2009-10-13 11:39:21 -0400, Sean Kelly <sean invisibleduck.org> said:
 
 I disagree about poor performance though.  With unique references or 
 move semantics, a copy of even complex data isn't necessary to ensure 
 that a message is passed safely.

Yeah, but for unique reference to be usable you need lent semantics, otherwise you can't make sure you're the unique holder once you call a function to do something with your unique object. Anything that use the reference could be storing it elsewhere: unique!Object o = new Object; o.doSomething(); How in the example above can I enforce that doSomething() won't escape the 'o' reference elsewhere? 'doSomething' could be made 'pure', but that trick will only work for one-argument functions (in the case above, the argument is the implicit 'this') because otherwise a pure function could leak the reference through another argument.

I honestly don't know how to enforce this-- I simply mentioned it because people have suggested it. Phobos already has assumeUnique() for converting to invariant, which is one option. I was hoping someone could suggest alternatives.
Oct 13 2009