[libc-commits] [libc] [libc] Apply scheduler attributes on thread creation (PR #225674)
Pavel Labath via libc-commits
libc-commits at lists.llvm.org
Mon Oct 12 02:55:58 PDT 2026
================
@@ -150,9 +151,29 @@ cleanup_thread_resources(ThreadAttributes *attrib) {
free_stack(attrib->stack, attrib->stacksize, attrib->guardsize);
}
+// Enum values used for controlling thread startup.
+enum class ClearTidState : FutexWordType {
+ EXITED = 0, // Set by the kernel when the thread exits.
+ WAITING, // Waiting for additional initialization.
+ RUNNING, // Initialization complete or not needed.
+ ABORT, // Initialization failed.
+};
+
static int start_thread(void *arg) {
auto *start_args = reinterpret_cast<StartArgs *>(arg);
auto *attrib = start_args->thread_attrib;
+ auto *clear_tid = static_cast<Futex *>(attrib->platform_data);
+
+ // If explicit scheduling parameters were requested, wait for the parent to
+ // apply them via setschedparam. If setschedparam fails, the parent signals
+ // ABORT, and the child exits immediately without running user code.
+ clear_tid->wait(static_cast<FutexWordType>(ClearTidState::WAITING),
+ cpp::nullopt, /*is_shared=*/false);
+ if (clear_tid->load(cpp::MemoryOrder::ACQUIRE) ==
+ static_cast<FutexWordType>(ClearTidState::ABORT)) {
+ LIBC_NAMESPACE::syscall_impl<long>(SYS_exit, 0);
----------------
labath wrote:
Done.
https://github.com/llvm/llvm-project/pull/225674
More information about the libc-commits
mailing list