[libc-commits] [libc] [libc] Implement barriers for pthreads (PR #148948)
Brooks Moses via libc-commits
libc-commits at lists.llvm.org
Fri Jul 18 14:23:26 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:
(Repeating offline conversation, for the record.)
I think the concept of one thread returning a special value is fairly pthreads-specific. C11 `threads.h` doesn't have a barrier functionality, and C++20's `std::barrier` doesn't return a value. And if this does end up needing to be used by a different threading API, it might be a different return value like returning the decremented thread count. So I would personally use the pthreads constant for it, until we find another thing that needs this return value.
For the second point -- you need to declare the variable as `static` to keep it from getting global linkage. With global linkage, it's no longer a compile-time constant since some other compilation unit could access it and change it.
https://github.com/llvm/llvm-project/pull/148948
More information about the libc-commits
mailing list