Skip to content

Commit fb2675f

Browse files
committed
Add implementation of exercise3-49
1 parent 65b91c5 commit fb2675f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
习题完成情况:
2626
- 章节一: 43/46
2727
- 章节二: 88/97
28-
- 章节三: 48/82
28+
- 章节三: 49/82
2929
- 章节四: TODO
3030
- 章节五: TODO
3131
* 运行

chapter3/exercise3-49.org

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#+LATEX_CLASS: ramsay-org-article
2+
#+LATEX_CLASS_OPTIONS: [oneside,A4paper,12pt]
3+
#+AUTHOR: Ramsay Leung
4+
5+
#+DATE: 2025-07-26 Sat 10:46
6+
7+
exercise3-48 能避免死锁的关键在于,我们提前知道所有需要获取的资源,并且通过 id 给了明确的顺序。
8+
9+
但是如果有需要动态获取的资源,那么就有可能死锁。
10+
11+
比如每个账户都可以有个「子账户」,只有在锁定账户之后,才可以读取子账户(才知道子账户是哪个),如果某些操作需要同时锁定父账户和子账户,那么就可能死锁:
12+
13+
- 进程1: 锁定账户a,发现它的子账户是账户b,尝试锁定账户b
14+
- 进程2: 锁定账户b,发现它的子账户是账户a,尝试锁定账户a
15+
16+
死锁

0 commit comments

Comments
 (0)