summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/testthread.d
blob: 139a891072cdc46a448e2d9ce6834871b0a43fb9 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
// PERMUTE_ARGS:

import core.stdc.stdio;
import core.thread;

version (CRuntime_DigitalMars)
{
    extern (C)
    {
        extern int _tlsstart;
        extern int _tlsend;
    }
}

int tlsx;

class Foo
{
    int x;

    void bar()
    {
        printf("bar()\n");
        assert(tlsx == 0);
        tlsx = 5;
        Thread t = Thread.getThis();

        version (CRuntime_DigitalMars)
            printf("thread ptr=%p, %p &tlsx = %p %p\n", t, &_tlsstart, &tlsx, &_tlsend);
        x = 3;
        printf("-bar()\n");
    }
}


int main()
{
    Foo f = new Foo();

    Thread t = new Thread(&f.bar);
    t.start();
    printf("t.start() done\n");
    // There is no analog for these in druntime.
    //t.pause();
    //t.resume();
    Thread.yield();
    t.join();
    printf("Done waiting\n");
    assert(f.x == 3);

    int i;
    Thread[5] tx;
    for (i = 0; i < tx.length; i++)
        tx[i] = new Thread(&f.bar);
    for (i = 0; i < tx.length; i++)
        tx[i].start();
    for (i = 0; i < tx.length; i++)
        tx[i].join();
    Thread.sleep(dur!"msecs"(1));

    printf("**Success**\n");
    return 0;
}