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