[vlc-devel] [PATCH 1/2] linux: fix vlc_futex_wait() cancellation

RĂ©mi Denis-Courmont remi at remlab.net
Mon Feb 3 20:32:38 CET 2020


As things stood, it works on Android (where the code is actually used)
but not on desktop. There is a latent bug where cancellation is not
acted up, leading to dead locks.
---
 src/linux/thread.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/linux/thread.c b/src/linux/thread.c
index 539c64f147..7e9dab63bd 100644
--- a/src/linux/thread.c
+++ b/src/linux/thread.c
@@ -60,7 +60,12 @@ static int vlc_futex_wake(void *addr, int nr)
 
 static int vlc_futex_wait(void *addr, unsigned val, const struct timespec *to)
 {
-    return sys_futex(addr, FUTEX_WAIT_PRIVATE, val, to, NULL, 0);
+    int ret, type;
+
+    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &type);
+    ret = sys_futex(addr, FUTEX_WAIT_PRIVATE, val, to, NULL, 0);
+    pthread_setcanceltype(type, NULL);
+    return ret;
 }
 
 void vlc_addr_signal(void *addr)
-- 
2.25.0



More information about the vlc-devel mailing list