Libraryless. Click here for Pure Java version (3091L/19K/76K).
!7 static Lock a = fairLock(); static Lock b = fairLock(); p-tt { centerHigherConsole(); doEvery_daemon(1000, r { L<ThreadInfo> lockingThreads = printDeadlocks(); if (nempty(lockingThreads)) { print("Interrupting locking threads."); L<Thread> threads = threadInfosToThreads(lockingThreads); if (nempty(threads)) { Thread t = random(threads); print("Interrupting thread " + quote(t.getName())); t.interrupt(); } } }); print("Initiating deadlock... :-)\n"); thread "A" { lock(a); try { print("Thread A has lock A."); sleep1Second(); print("Thread A getting lock B."); lock(b); try { print("Thread A successful!"); } finally { b.unlock(); } } finally { a.unlock(); } } thread "B" { lock(b); try { print("Thread B has lock B."); sleep1Second(); print("Thread B getting lock A."); lock(a); try { print("Thread B successful!"); } finally { a.unlock(); } } finally { b.unlock(); } } sleepQuietly(); }
Began life as a copy of #1009314
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1009315 |
| Snippet name: | Try to solve ReentrantLock deadlock by interrupting a random thread when using lockInterruptibly() [WORKS] |
| Eternal ID of this version: | #1009315/4 |
| Text MD5: | c782f0d610023ddf8346b308c96e2c9a |
| Transpilation MD5: | 9f2ab688b8d4256badbf7907d4d5a18e |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-06-03 02:32:24 |
| Source code size: | 1203 bytes / 59 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 704 / 884 |
| Version history: | 3 change(s) |
| Referenced in: | [show references] |