Commit 389875d
committed
Change the implementation of mutex to test and set
1. Directly show the scenarios using Test and Set and
its atomic operations.
- Use `atomic_flag_test_and_set()` and `atomic_flag_clear()` to
implement the original mutex lock and unlock mechanism.
- Replace the original condition variable wait mechanism with
`atomic_flag_test_and_set()` combined with a `while` loop.
2. Avoid deadlock in `tpool_future_get()`.
- The main thread must first wait for the worker to complete the "BBP
formula" job.
- Subsequently, it should wait for the worker to unlock.
- These two operations must occur in this order to avoid deadlock.
Swapping them will lead to deadlock.1 parent 267f1ad commit 389875d
2 files changed
+14
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | | - | |
55 | | - | |
| 53 | + | |
56 | 54 | | |
57 | 55 | | |
58 | 56 | | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
67 | 65 | | |
68 | 66 | | |
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
72 | | - | |
| 70 | + | |
| 71 | + | |
73 | 72 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | 73 | | |
78 | 74 | | |
79 | | - | |
| 75 | + | |
80 | 76 | | |
81 | 77 | | |
82 | 78 | | |
| |||
102 | 98 | | |
103 | 99 | | |
104 | 100 | | |
105 | | - | |
106 | | - | |
| 101 | + | |
| 102 | + | |
107 | 103 | | |
108 | 104 | | |
109 | | - | |
110 | 105 | | |
111 | | - | |
| 106 | + | |
112 | 107 | | |
113 | 108 | | |
114 | 109 | | |
| |||
248 | 243 | | |
249 | 244 | | |
250 | 245 | | |
251 | | - | |
252 | 246 | | |
253 | 247 | | |
254 | 248 | | |
| |||
0 commit comments