Joe Duffy on concurrency

Meta via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 1 11:19:47 PST 2016


On Thursday, 1 December 2016 at 18:56:36 UTC, qznc wrote:
> On Thursday, 1 December 2016 at 12:17:46 UTC, Barry wrote:
>> http://joeduffyblog.com/2016/11/30/15-years-of-concurrency/
>
>
>
>> delegate void PureFunc<T>() immutable;
>
>> This meant that a lambda conforming to the PureFunc interface 
>> could only close over immutable state.
>
>> Notice how powerful this has suddenly become! This PureFunc is 
>> precisely what we would want for a parallel task. As we will 
>> see shortly, these simple concepts alone are enough to enable 
>> many of those PFX abstractions to become safe.
>
> That is an interesting idea. Afaik, D does not allow to limit 
> closure like this?

Actually it does, and it works the exact same way as far as I can 
tell.

void main()
{
	int n;
	
	int nested() immutable
	{
		return n; //Error: immutable function 'f761.main.nested' cannot 
access mutable data 'n'
	}
	
	auto del = () immutable => n; //Error: immutable delegate 
'f761.main.__dgliteral2' cannot access mutable data 'n'
}


More information about the Digitalmars-d mailing list