[libc-commits] [libc] [libc] Implement barriers for pthreads (PR #148948)

Uzair Nawaz via libc-commits libc-commits at lists.llvm.org
Tue Jul 22 13:48:20 PDT 2025


================
@@ -0,0 +1,117 @@
+//===-- Tests for pthread_barrier_t ---------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/pthread/pthread_barrier_destroy.h"
+#include "src/pthread/pthread_barrier_init.h"
+#include "src/pthread/pthread_barrier_wait.h"
+
+#include "src/__support/CPP/atomic.h"
+#include "src/pthread/pthread_create.h"
+#include "src/pthread/pthread_join.h"
+#include "src/pthread/pthread_mutex_destroy.h"
+#include "src/pthread/pthread_mutex_init.h"
+#include "src/pthread/pthread_mutex_lock.h"
+#include "src/pthread/pthread_mutex_unlock.h"
+#include "src/stdio/printf.h"
+
+#include "test/IntegrationTest/test.h"
+
+#include <pthread.h>
+
+pthread_barrier_t barrier;
----------------
uzairnawaz wrote:

Since I now have a single function being used for two tests (the parameterized single_use_barrier_test function), it makes it awkward to use a unique barrier for each test. I could pass it as a parameter to the test function and also a parameter to the relevant threads, but I think an easier solution may be to just memset the barrier to 0 at the beginning of each test before calling `pthread_barrier_init`, and that should solve this potential issue. Let me know if you disagree/feel differently!

https://github.com/llvm/llvm-project/pull/148948


More information about the libc-commits mailing list