summaryrefslogtreecommitdiff
path: root/lib/frr_pthread.h
diff options
context:
space:
mode:
authorMark Stapp <mjs@cisco.com>2024-04-09 08:51:20 -0400
committerMark Stapp <mjs@cisco.com>2024-04-11 09:00:58 -0400
commit44eb133b527dc113c75d419bf062517d8cdb3ad9 (patch)
tree39b26ebb2e2d4561fc29cc506712aae05647c85a /lib/frr_pthread.h
parente19fa07c2c92a84e89d0b08cc735ac16e699b3b3 (diff)
lib: serialize pthread startup
Add a new condition var and mutex to serialize pthread startup. When a new pthread is started, it will wait very early on for the parent pthread to permit it to run. This ensures that that the ordering between parent and child is predictable. Signed-off-by: Mark Stapp <mjs@cisco.com>
Diffstat (limited to 'lib/frr_pthread.h')
-rw-r--r--lib/frr_pthread.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h
index 1e1b8d7fd3..bb751b7071 100644
--- a/lib/frr_pthread.h
+++ b/lib/frr_pthread.h
@@ -47,6 +47,17 @@ struct frr_pthread {
struct frr_pthread_attr attr;
/*
+ * Startup serialization: newly-started pthreads wait at a point
+ * very early in life so that there isn't a race with the
+ * starting pthread. The OS 'start' apis don't make any guarantees
+ * about which pthread runs first - the existing pthread that has
+ * called the 'start' api, or the new pthread that is just starting.
+ */
+ pthread_cond_t startup_cond;
+ pthread_mutex_t startup_cond_mtx;
+ atomic_bool started;
+
+ /*
* Notification mechanism for allowing pthreads to notify their parents
* when they are ready to do work. This mechanism has two associated
* functions: