diff options
author | Araq <rumpf_a@web.de> | 2011-06-02 13:02:40 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-06-02 13:02:40 +0200 |
commit | 3260702a6044cdae89cf673ad1983aa3342127de (patch) | |
tree | 40439bfaf9f4ecb4929547e387998b282eee408c /tests/accept/run | |
parent | d0bfc3665fd0131dad516d2fcd7cfe73c3a6f122 (diff) | |
download | Nim-3260702a6044cdae89cf673ad1983aa3342127de.tar.gz |
first steps to thread local heaps
Diffstat (limited to 'tests/accept/run')
-rwxr-xr-x | tests/accept/run/tnodeadlocks.nim | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/accept/run/tnodeadlocks.nim b/tests/accept/run/tnodeadlocks.nim new file mode 100755 index 000000000..6d5a57c86 --- /dev/null +++ b/tests/accept/run/tnodeadlocks.nim @@ -0,0 +1,69 @@ +discard """ + outputsub: "101" +""" + +import os + +const + noDeadlocks = defined(system.deadlocksPrevented) + +var + thr: array [0..5, TThread[tuple[a, b: int]]] + L, M, N: TLock + +proc doNothing() = nil + +proc threadFunc(interval: tuple[a, b: int]) {.procvar.} = + doNothing() + for i in interval.a..interval.b: + when nodeadlocks: + case i mod 6 + of 0: + Aquire(L) # lock stdout + Aquire(M) + Aquire(N) + of 1: + Aquire(L) + Aquire(N) # lock stdout + Aquire(M) + of 2: + Aquire(M) + Aquire(L) + Aquire(N) + of 3: + Aquire(M) + Aquire(N) + Aquire(L) + of 4: + Aquire(N) + Aquire(M) + Aquire(L) + of 5: + Aquire(N) + Aquire(L) + Aquire(M) + else: assert false + else: + Aquire(L) # lock stdout + Aquire(M) + + echo i + os.sleep(10) + when nodeadlocks: + echo "deadlocks prevented: ", deadlocksPrevented + when nodeadlocks: + Release(N) + Release(M) + Release(L) + +InitLock(L) +InitLock(M) +InitLock(N) + +proc main = + for i in 0..high(thr): + createThread(thr[i], threadFunc, (i*100, i*100+50)) + joinThreads(thr) + +main() + |