aboutsummaryrefslogtreecommitdiff
path: root/libphobos/testsuite/libphobos.thread/tlsstack.d
blob: 7b76f22fa920f25a5a93eec6555c7cec76973041 (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
module core.thread.test; // needs access to getStackTop()/getStackBottom()

import core.stdc.stdio : printf;
import core.thread;

ubyte[16384] data;

void showThreadInfo() nothrow
{
    try
    {
        auto top = getStackTop();
        auto bottom = getStackBottom();
        printf("tlsdata:     %p\n", data.ptr);
        printf("stack top:   %p\n", getStackTop());
        printf("stack bottom:%p\n", getStackBottom());
        printf("used stack:  %lld\n", cast(ulong)(bottom - top));
    }
    catch(Exception e)
    {
        assert(false, e.msg);
    }
}

void main()
{
    printf("### main\n");
    showThreadInfo();

    printf("### thread\n");
    auto th = new Thread(&showThreadInfo, 16384);
    th.start();
    th.join();

    printf("### lowlevel thread\n");
    auto llth = createLowLevelThread(() { showThreadInfo(); });
    joinLowLevelThread(llth);
}