Debian Codegraph @

gcc/testsuite/gdc.test/runnable/testthread.d

raw
1 // PERMUTE_ARGS:
2
3 import core.stdc.stdio;
4 import core.thread;
5
6 int tlsx;
7
8 class Foo
9 {
10 int x;
11
12 void bar()
13 {
14 printf("bar()\n");
15 assert(tlsx == 0);
16 tlsx = 5;
17 Thread t = Thread.getThis();
18
19 x = 3;
20 printf("-bar()\n");
21 }
22 }
23
24
25 int main()
26 {
27 Foo f = new Foo();
28
29 Thread t = new Thread(&f.bar);
30 t.start();
31 printf("t.start() done\n");
32 // There is no analog for these in druntime.
33 //t.pause();
34 //t.resume();
35 Thread.yield();
36 t.join();
37 printf("Done waiting\n");
38 assert(f.x == 3);
39
40 int i;
41 Thread[5] tx;
42 for (i = 0; i < tx.length; i++)
43 tx[i] = new Thread(&f.bar);
44 for (i = 0; i < tx.length; i++)
45 tx[i].start();
46 for (i = 0; i < tx.length; i++)
47 tx[i].join();
48 Thread.sleep(dur!"msecs"(1));
49
50 printf("**Success**\n");
51 return 0;
52 }