xref: /netbsd-src/external/gpl3/gcc.old/dist/libphobos/testsuite/libphobos.thread/tlsgc_sections.d (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1 final class Class
2 {
3     // This gets triggered although the instance always stays referenced.
~this()4     ~this()
5     {
6         import core.stdc.stdlib;
7         abort();
8     }
9 }
10 
11 Class obj;
12 
this()13 static this()
14 {
15     obj = new Class;
16 }
17 
~this()18 static ~this()
19 {
20     // Free without destruction to avoid triggering abort()
21     import core.memory;
22     GC.free(cast(void*)obj);
23 }
24 
doit()25 void doit()
26 {
27     foreach (i; 0 .. 10_000)
28         new ubyte[](100_000);
29 }
30 
main()31 void main()
32 {
33     import core.thread;
34     auto t = new Thread(&doit);
35     t.start();
36 
37     // This triggers the GC that frees the still referenced Class instance.
38     doit();
39 }
40