Skip to content

LibC: Align PTHREAD_COND_INITIALIZER with pthread_cond_init - #27019

Open
LucasChollet wants to merge 1 commit into
SerenityOS:masterfrom
LucasChollet:pthread-fix
Open

LibC: Align PTHREAD_COND_INITIALIZER with pthread_cond_init#27019
LucasChollet wants to merge 1 commit into
SerenityOS:masterfrom
LucasChollet:pthread-fix

Conversation

@LucasChollet

Copy link
Copy Markdown
Member

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

@github-actions github-actions Bot added the 馃憖 pr-needs-review PR needs review from a maintainer or community member label Sep 8, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

馃憖 pr-needs-review PR needs review from a maintainer or community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant