好消息, 死锁是确定性的.
Last active
April 11, 2018 05:33
-
-
Save BUNotesAI/6c80eed40a4b3b9665a4a04dadfe5f93 to your computer and use it in GitHub Desktop.
promise 确定性死锁
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; | |
| ;;Executor线程池多次执行方法 | |
| ;; | |
| (import 'java.util.concurrent.Executors) | |
| (def thread-pool (Executors/newFixedThreadPool (+ 2 (.availableProcessors (Runtime/getRuntime))))) | |
| (defn dothreads! [f & {thread-count :threads | |
| exec-count :times | |
| :or {thread-count 1 exec-count 1}}] | |
| (dotimes [t thread-count] | |
| (.submit thread-pool #(dotimes [c exec-count] (f c))))) | |
| ;; 确定性死锁 | |
| (def alex (promise)) | |
| (def kate (promise)) | |
| (dothreads! (println "alex has " @alex) (deliver kate :thinking)) | |
| (dothreads! (println "kate has " @kate ) (deliver alex :fork)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment