[dmd-concurrency] synchronized, shared, and regular methods inside the same class

Michel Fortin michel.fortin at michelf.com
Tue Jan 5 19:18:17 PST 2010


Le 2010-01-05 à 20:12, Sean Kelly a écrit :

> Michel Fortin wrote:
> 
>> I think my proposal is completely implementable right now.

> 
> It is.  The only tricky thing about shared variables which may or may not be trickier with a struct is that copying them is kind of weird.  Copying a shared value type makes the result non-shared.  I guess the struct would have a reference to the shared value and be non-copyable for correctness.


Yes, the struct would hold a reference to the shared value and be non-copyable. It should not be possible to store the temporary struct into a variable; you should be forced to write atomic() once for each atomic operation:

	atomic(y) = 3 + atomic(y); // two distinct atomic operations

	atomic(y) += 3; // this one is actually atomic

	auto z = atomic(y);
	z = 3 + z; // misleading, z should not be allowed to exist


>> For cases where you don't really want atomic operations, it should be explicit too. Perhaps we could define another function in the same style for reads and and writes with no barrier:
>> 
>> 	atomic(y) = 10; // with write barrier
>> 	latent(y) = 20; // no write barrier, subject to propagation latency
> 
> In the atomics lib I wrote, it's possible to specify the memory barrier used for each operation. I'm not sure how this would work into the operator overloading approach though.

Perhaps this way:

	atomic(y) = 10;
	atomic!rel(y) = 10;
	atomic!seq(y) = 10;
	atomic!acq(y) = 10;
	atomic!ssb(y) = 10;
	...
	latent(y) = 10;

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





More information about the dmd-concurrency mailing list