Commit 7930b49
committed
Cygwin: thread: Allow fast_mutex to be acquired multiple times.
Previously, the fast_mutex defined in thread.h could not be aquired
multiple times, i.e., the thread causes deadlock if it attempted to
acquire a lock already acquired by the thread. For example, a deadlock
occurs if another pthread_key_create() is called in the destructor
specified in the previous pthread_key_create(). This is because the
run_all_destructors() calls the desructor via keys.for_each() where
both for_each() and pthread_key_create() (that calls List_insert())
attempt to acquire the lock. With this patch, the fast_mutex can be
acquired multiple times by the same thread similar to the behaviour
of a Windows mutex. In this implementation, the mutex is released
only when the number of unlock() calls matches the number of lock()
calls.
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257705.html
Fixes: 1a82139 ("fix race condition in List_insert")
Reported-by: Yuyi Wang <[email protected]>
Reviewed-by: Corinna Vinschen <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>1 parent dcb12dd commit 7930b49
1 file changed
+14
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
68 | 78 | | |
| 79 | + | |
| 80 | + | |
69 | 81 | | |
70 | 82 | | |
71 | 83 | | |
| |||
0 commit comments