Fixing tail mutable TLS/field initializers

Dukc ajieskola at gmail.com
Wed Jun 12 21:51:08 UTC 2024


Nick Treleaven kirjoitti 7.6.2024 klo 14.05:
> ```d
> int[] x = [1, 2, 3];
> ```
> The above is really like:
> ```d
> __gshared gsx = [1, 2, 3];
> int[] x = gsx;
> ```
> [snip]

Unless we want to disallow array literals for mutable static variables, 
there's really only one solution: the array has to be duplicated at 
module initialisation time, any time a thread is initialised:

```d
__gshared gsx = [1, 2, 3];
int[] x;

static this()
{   x = gsx.dup;
}
```



More information about the dip.ideas mailing list