Limit dg-xfail-run-if for *-*-hpux11.[012]* to -O0
[official-gcc.git] / libphobos / testsuite / libphobos.allocations / tls_gc_integration.d
blob7c084abcaf109617d32d0d288203d52c4f076091
1 import core.memory, core.thread, core.volatile;
3 /*
4 * This test repeatedly performs operations on GC-allocated objects which
5 * are only reachable from TLS storage. Tests are performed in multiple threads
6 * and GC collections are triggered repeatedly, so if the GC does not properly
7 * scan TLS memory, this provokes a crash.
8 */
9 class TestTLS
11 uint a;
12 void addNumber()
14 auto val = volatileLoad(&a);
15 val++;
16 volatileStore(&a, val);
20 TestTLS tlsPtr;
22 static this()
24 tlsPtr = new TestTLS();
27 void main()
29 void runThread()
31 for (size_t i = 0; i < 100; i++)
33 Thread.sleep(10.msecs);
34 tlsPtr.addNumber();
35 GC.collect();
39 Thread[] threads;
40 for (size_t i = 0; i < 20; i++)
42 auto t = new Thread(&runThread);
43 threads ~= t;
44 t.start();
46 runThread();
48 foreach (thread; threads)
49 thread.join();