1import core.sys.posix.pthread;
2import core.memory;
3import core.thread;
4
5extern (C) void  rt_moduleTlsCtor();
6extern (C) void  rt_moduleTlsDtor();
7
8extern(C)
9void* entry_point1(void*)
10{
11    // try collecting - GC must ignore this call because this thread
12    // is not registered in runtime
13    GC.collect();
14    return null;
15}
16
17extern(C)
18void* entry_point2(void*)
19{
20    // This thread gets registered in druntime, does some work and gets
21    // unregistered to be cleaned up manually
22    thread_attachThis();
23    rt_moduleTlsCtor();
24
25    auto x = new int[10];
26
27    rt_moduleTlsDtor();
28    thread_detachThis();
29    return null;
30}
31
32void main()
33{
34    // allocate some garbage
35    auto x = new int[1000];
36
37    {
38        pthread_t thread;
39        auto status = pthread_create(&thread, null, &entry_point1, null);
40        assert(status == 0);
41        pthread_join(thread, null);
42    }
43
44    {
45        pthread_t thread;
46        auto status = pthread_create(&thread, null, &entry_point2, null);
47        assert(status == 0);
48        pthread_join(thread, null);
49    }
50}
51