dg1 fails because `i` is not shared.
You would expect dg2 to fail as well. Somehow because `j` is an TLS variable however, it is suddenly fine.
```
void main() @safe {
int i = 1;
static int j = 2;
auto dg1 = () shared @safe => i; // error
auto dg2 = () shared @safe => j; // no error??
}
```
Comment #1 by dfj1esp02 — 2022-08-30T15:16:00Z
The shared attribute on the delegate applies to captured closure variables. TLS isn't part of closure context, in a way it's stored in the thread, not in the closure. Normal shared methods can access TLS just fine too.
Comment #2 by robert.schadek — 2024-12-13T19:24:18Z