[dmd-concurrency] shared arrays

Michel Fortin michel.fortin at michelf.com
Thu Jan 14 19:11:51 PST 2010


Le 2010-01-14 à 22:01, Andrei Alexandrescu a écrit :

> Michel Fortin wrote:
>> Le 2010-01-14 à 18:07, Andrei Alexandrescu a écrit :
>>> Unfortunately, this(this) is called after the bits have been
>>> copied, so if there was any tearing, it already happened. I don't
>>> know how we can solve this.
>> Where is the copy-constructor when we need one? :-)
> 
> I realized that fortunately that's not a problem: during memcpy, the target is not yet shared. Whew. So it all holds water.
> 
> this(this) shared { ... }
> 
> should work.

But the source is shared. Couldn't it be updated while memcpy does its work, creating an incoherent state? Something like: memcpy copies half of it, context switch, other thread update first and last bytes, context switch, memcpy finishes its work. Result, last byte of the copy doesn't match first byte.


>> Now, the really tricky question is should this one be copyable when
>> shared:
>> struct D { immutable string a; long b; }
>> Since 'a' is immutable, you don't need to copy it atomically, only
>> 'b' requires an atomic copy. So copying the struct "atomically" is
>> possible by copying 'a' normally and 'b' atomically. Now, is that
>> going to be supported?
> 
> But long isn't atomically copyable. Did you mean int?

Well, that depends on the architecture. I meant a type which is atomically copyable yes.


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





More information about the dmd-concurrency mailing list