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

Brooks Moses via libc-commits libc-commits at lists.llvm.org
Thu Jul 17 12:47:19 PDT 2025


================
@@ -0,0 +1,83 @@
+//===-- Implementation of Barrier class ------------- ---------------------===//
+//
+// 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/__support/threads/barrier.h"
+#include "barrier.h"
+#include "hdr/errno_macros.h"
+#include "src/__support/threads/mutex.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+const int BARRIER_FIRST_EXITED = -1;
----------------
brooksmoses wrote:

Why not just use `PTHREAD_BARRIER_SERIAL_THREAD` here, and avoid the special-case logic in `pthread_barrier_wait`?

Also note that by defining it this way, you're using global storage to store the value (and then loading it from memory every time `pthread_barrier_wait` is called), rather than just inlining it in the code.  That's a bit unnecessary, and introduces the possibility that something could cast away the const-ness and change it.

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


More information about the libc-commits mailing list