shared - i need it to be useful

Nicholas Wilson iamthewilsonator at hotmail.com
Mon Oct 15 21:03:01 UTC 2018


On Monday, 15 October 2018 at 20:54:12 UTC, jmh530 wrote:
> On Monday, 15 October 2018 at 20:44:35 UTC, Manu wrote:
>> snip
>>
>> Are you saying `is(immutable(int) == shared) == true)` ??
>
> From the spec:
> "Applying any qualifier to immutable T results in immutable T. 
> This makes immutable a fixed point of qualifier combinations 
> and makes types such as const(immutable(shared T)) impossible 
> to create."
>
> Example:
>
> import std.stdio : writeln;
>
> void main()
> {
>     writeln(is(immutable(int) == shared immutable(int)) == 
> true); //prints true
> }

The philosophy of this is that: the value never changes, 
therefore only one copy of the variable needs to exist (i.e. 
immutable variables declared at module scope are _not_ thread 
local) and can be shared between threads with no race conditions.

I'm saying that while what you propose sounds very reasonable, we 
should make sure that reading immutable variables is still good ;)


More information about the Digitalmars-d mailing list