[ovs-dev] [PATCH v2 6/8] ovs-thread: Quiesce when joining pthreads

Gaetan Rivet grive at u256.net
Thu May 20 13:35:50 UTC 2021


Joining pthreads makes the caller quiescent. It should register as such,
as joined threads may wait on an RCU callback executing before quitting,
deadlocking the caller.

Signed-off-by: Gaetan Rivet <grive at u256.net>
---
 lib/ovs-thread.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 805cba622..bf58923f8 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -180,8 +180,6 @@ XPTHREAD_FUNC1(pthread_cond_destroy, pthread_cond_t *);
 XPTHREAD_FUNC1(pthread_cond_signal, pthread_cond_t *);
 XPTHREAD_FUNC1(pthread_cond_broadcast, pthread_cond_t *);
 
-XPTHREAD_FUNC2(pthread_join, pthread_t, void **);
-
 typedef void destructor_func(void *);
 XPTHREAD_FUNC2(pthread_key_create, pthread_key_t *, destructor_func *);
 XPTHREAD_FUNC1(pthread_key_delete, pthread_key_t);
@@ -191,6 +189,20 @@ XPTHREAD_FUNC2(pthread_setspecific, pthread_key_t, const void *);
 XPTHREAD_FUNC3(pthread_sigmask, int, const sigset_t *, sigset_t *);
 #endif
 
+void
+xpthread_join(pthread_t thread, void **retval)
+{
+    int error;
+
+    ovsrcu_quiesce_start();
+    error = pthread_join(thread, retval);
+    ovsrcu_quiesce_end();
+
+    if (OVS_UNLIKELY(error)) {
+        ovs_abort(error, "%s failed", __func__);
+    }
+}
+
 static void
 ovs_mutex_init__(const struct ovs_mutex *l_, int type)
 {
-- 
2.31.1



More information about the dev mailing list