LibC: Align PTHREAD_COND_INITIALIZER with pthread_cond_init - #27019
Open
LucasChollet wants to merge 1 commit into
Open
LibC: Align PTHREAD_COND_INITIALIZER with pthread_cond_init#27019LucasChollet wants to merge 1 commit into
LucasChollet wants to merge 1 commit into
Conversation
According to POSIX: "In cases where default condition variable attributes are appropriate, the macro PTHREAD_COND_INITIALIZER can be used to initialise condition variables that are statically allocated. The effect is equivalent to dynamic initialisation by a call to pthread_cond_init() with parameter attr specified as NULL, except that no error checks are performed." AFAICT, the clock choice is left as an implementation detail, but other systems seem to use CLOCK_REALTIME as the default: https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_cond_init.c https://github.com/openbsd/src/blob/7da33d17d09f1f2c0e27643875d90dc64f79173c/lib/libc/thread/rthread_cond.c#L30-L47
LucasChollet
force-pushed
the
pthread-fix
branch
from
September 8, 2026 12:07
f589a77 to
61a38c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
According to POSIX:
"In cases where default condition variable attributes are appropriate, the macro PTHREAD_COND_INITIALIZER can be used to initialise condition variables that are statically allocated. The effect is equivalent to dynamic initialisation by a call to pthread_cond_init() with parameter attr specified as NULL, except that no error checks are performed."
AFAICT, the clock choice is left as an implementation detail, but other systems seem to use CLOCK_REALTIME as the default:
https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_cond_init.c;h=688bcae5de5a6d0ecad2115ac486891961e2854a;hb=e474366724369f6371f32a4a05a1311d311ec2ae
https://github.com/openbsd/src/blob/7da33d17d09f1f2c0e27643875d90dc64f79173c/lib/libc/thread/rthread_cond.c#L30-L47
This fixes 25 libcxx tests:
std/thread/futures/futures.shared_future/wait_for.pass.cpp
std/thread/futures/futures.shared_future/wait_until.pass.cpp
std/thread/futures/futures.unique_future/wait_for.pass.cpp
std/thread/futures/futures.unique_future/wait_until.pass.cpp
std/thread/thread.condition/thread.condition.condvar/wait_for.pass.cpp
std/thread/thread.condition/thread.condition.condvar/wait_for_pred.pass.cpp
std/thread/thread.condition/thread.condition.condvar/wait_until.pass.cpp
std/thread/thread.condition/thread.condition.condvar/wait_until_pred.pass.cpp
std/thread/thread.condition/thread.condition.condvarany/wait_for.pass.cpp
std/thread/thread.condition/thread.condition.condvarany/wait_for_pred.pass.cpp
std/thread/thread.condition/thread.condition.condvarany/wait_for_token_pred.pass.cpp
std/thread/thread.condition/thread.condition.condvarany/wait_until.pass.cpp
std/thread/thread.condition/thread.condition.condvarany/wait_until_pred.pass.cpp
std/thread/thread.condition/thread.condition.condvarany/wait_until_token_pred.pass.cpp
std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp
std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp
std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp
std/thread/thread.threads/thread.thread.this/sleep_until.pass.cpp