diff options
author | Johannes Pfau <johannespfau@gmail.com> | 2019-04-25 11:11:39 +0000 |
---|---|---|
committer | Johannes Pfau <jpfau@gcc.gnu.org> | 2019-04-25 11:11:39 +0000 |
commit | 9168f22057a72822f0d2ca5b1053e97becd649fa (patch) | |
tree | 687c80f5f3eb4cfe35d64eaf588ccd3d1a8e047c /libphobos/testsuite | |
parent | 7da021f080b23bbfe6206855a40a73e145f10b75 (diff) |
D: Implement GCC emutls in druntime
* libdruntime/Makefile.am: Add emutls and gthread files.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/gcc/emutls.d: New file. Implement GC-compatible emutls.
* libdruntime/gcc/gthread.d: New file.
* libdruntime/gcc/sections/elf_shared.d: Integrate emutls support.
* testsuite/libphobos.allocations/tls_gc_integration.d: New test for
TLS.
From-SVN: r270568
Diffstat (limited to 'libphobos/testsuite')
-rw-r--r-- | libphobos/testsuite/libphobos.allocations/tls_gc_integration.d | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libphobos/testsuite/libphobos.allocations/tls_gc_integration.d b/libphobos/testsuite/libphobos.allocations/tls_gc_integration.d new file mode 100644 index 00000000000..44eb40c366d --- /dev/null +++ b/libphobos/testsuite/libphobos.allocations/tls_gc_integration.d @@ -0,0 +1,50 @@ +import core.memory, core.thread, core.bitop; + +/* + * This test repeatedly performs operations on GC-allocated objects which + * are only reachable from TLS storage. Tests are performed in multiple threads + * and GC collections are triggered repeatedly, so if the GC does not properly + * scan TLS memory, this provokes a crash. + */ +class TestTLS +{ + uint a; + void addNumber() + { + auto val = volatileLoad(&a); + val++; + volatileStore(&a, val); + } +} + +TestTLS tlsPtr; + +static this() +{ + tlsPtr = new TestTLS(); +} + +void main() +{ + void runThread() + { + for (size_t i = 0; i < 100; i++) + { + Thread.sleep(10.msecs); + tlsPtr.addNumber(); + GC.collect(); + } + } + + Thread[] threads; + for (size_t i = 0; i < 20; i++) + { + auto t = new Thread(&runThread); + threads ~= t; + t.start(); + } + runThread(); + + foreach (thread; threads) + thread.join(); +} |