Index | Thread | Search

From:
Mark Kettenis <mark.kettenis@xs4all.nl>
Subject:
Re: mention mutex in pthread_cond_init.3?
To:
Job Snijders <job@openbsd.org>
Cc:
tech@openbsd.org
Date:
Fri, 20 Jun 2025 16:11:44 +0200

Download raw body.

Thread
> Date: Fri, 20 Jun 2025 13:25:15 +0000
> From: Job Snijders <job@openbsd.org>
> 
> Dear Guehnther / Tedu,
> 
> As I understand it, a mutex must be used to protect the condition
> variable itself. So I think the below might help clarify the
> relationship between conditions and mutexes. OK?

Yes, see pthread_cond_wait(3).  But I don't think adding this here
helps in any way.

> Index: ./man/pthread_cond_init.3
> ===================================================================
> RCS file: /cvs/src/lib/libpthread/man/pthread_cond_init.3,v
> diff -u -p -r1.13 pthread_cond_init.3
> --- ./man/pthread_cond_init.3	7 Jun 2025 00:16:52 -0000	1.13
> +++ ./man/pthread_cond_init.3	20 Jun 2025 13:20:56 -0000
> @@ -50,6 +50,8 @@ If
>  is
>  .Dv NULL ,
>  the default attributes are used.
> +.Pp
> +A condition variable must always be used in conjunction with a mutex.
>  .Sh RETURN VALUES
>  If successful, the
>  .Fn pthread_cond_init
> @@ -76,7 +78,8 @@ variable.
>  .Xr pthread_cond_destroy 3 ,
>  .Xr pthread_cond_signal 3 ,
>  .Xr pthread_cond_timedwait 3 ,
> -.Xr pthread_cond_wait 3
> +.Xr pthread_cond_wait 3 ,
> +.Xr pthread_mutex_init 3
>  .Sh STANDARDS
>  .Fn pthread_cond_init
>  conforms to
> 
>