* [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERM
@ 2024-10-09 12:53 Jan Kratochvil
2024-10-10 10:32 ` Florian Weimer
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2024-10-09 12:53 UTC (permalink / raw)
To: Alejandro Colomar; +Cc: linux-man
[-- Attachment #1: Type: text/plain, Size: 205 bytes --]
pthread_cond_wait and pthread_cond_timedwait can also return EPERM
Attached a reproducer.
I did not test the EINTR case but it looks logical to me.
Signed-off-by: Jan Kratochvil <jan@jankratochvil.net>
[-- Attachment #2: wait.c --]
[-- Type: text/plain, Size: 510 bytes --]
#define _GNU_SOURCE
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(void) {
// pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; // not reproducible
pthread_mutex_t mut = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
int err;
// err=pthread_mutex_lock(&mut);
// assert(!err);
err=pthread_cond_wait(&cond, &mut);
if (err) {
printf("%d=%s\n",err,strerror(err));
return 1;
}
return 0;
}
[-- Attachment #3: pthread_cond_init.3.patch --]
[-- Type: text/plain, Size: 919 bytes --]
diff --git a/man/man3/pthread_cond_init.3 b/man/man3/pthread_cond_init.3
index 42e7eac..6e21b54 100644
--- a/man/man3/pthread_cond_init.3
+++ b/man/man3/pthread_cond_init.3
@@ -141,15 +141,28 @@ and a non-zero error code on error.
.
.SH ERRORS
\fBpthread_cond_init\fP,
-\fBpthread_cond_signal\fP,
-\fBpthread_cond_broadcast\fP,
-and \fBpthread_cond_wait\fP
+\fBpthread_cond_signal\fP
+and \fBpthread_cond_broadcast\fP,
never return an error code.
.P
+The \fBpthread_cond_wait\fP function returns
+the following error codes on error:
+.RS
+.TP
+\fBEPERM\fP
+\fBmutex\fP is not locked.
+.TP
+\fBEINTR\fP
+\fBpthread_cond_wait\fP was interrupted by a signal.
+.RE
+.P
The \fBpthread_cond_timedwait\fP function returns
the following error codes on error:
.RS
.TP
+\fBEPERM\fP
+\fBmutex\fP is not locked.
+.TP
\fBETIMEDOUT\fP
The condition variable was not signaled
until the timeout specified by \fIabstime\fP.
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERM
2024-10-09 12:53 [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERM Jan Kratochvil
@ 2024-10-10 10:32 ` Florian Weimer
2024-10-10 11:46 ` [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal Jan Kratochvil
0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2024-10-10 10:32 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Alejandro Colomar, linux-man
* Jan Kratochvil:
> +\fBEINTR\fP
> +\fBpthread_cond_wait\fP was interrupted by a signal.
> +.RE
POSIX specifically disallows returning EINTR. Applications cannot
expect that pthread_cond_wait returns upon delivery of a signal. Such
a return is only possible due to the general allowance for spurious
wakeups, and must result in a zero result.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal
2024-10-10 10:32 ` Florian Weimer
@ 2024-10-10 11:46 ` Jan Kratochvil
2024-10-10 12:25 ` Florian Weimer
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2024-10-10 11:46 UTC (permalink / raw)
To: Florian Weimer; +Cc: Alejandro Colomar, linux-man
[-- Attachment #1: Type: text/plain, Size: 726 bytes --]
On Thu, 10 Oct 2024 18:32:51 +0800, Florian Weimer wrote:
> * Jan Kratochvil:
>
> > +\fBEINTR\fP
> > +\fBpthread_cond_wait\fP was interrupted by a signal.
> > +.RE
>
> POSIX specifically disallows returning EINTR. Applications cannot
> expect that pthread_cond_wait returns upon delivery of a signal. Such
> a return is only possible due to the general allowance for spurious
> wakeups, and must result in a zero result.
OK, I agree when I tried that. So I have removed this part.
But then I believe the EINTR presence at pthread_cond_timedwait documentation
is also wrong (I did not change that in this patch) as I could not reproduce
the EINTR (attached).
Jan
Signed-off-by: Jan Kratochvil <jan@jankratochvil.net>
[-- Attachment #2: pthread_cond_init.3.patch --]
[-- Type: text/plain, Size: 847 bytes --]
diff --git a/man/man3/pthread_cond_init.3 b/man/man3/pthread_cond_init.3
index 42e7eac..fa4c6f6 100644
--- a/man/man3/pthread_cond_init.3
+++ b/man/man3/pthread_cond_init.3
@@ -141,15 +141,25 @@ and a non-zero error code on error.
.
.SH ERRORS
\fBpthread_cond_init\fP,
-\fBpthread_cond_signal\fP,
-\fBpthread_cond_broadcast\fP,
-and \fBpthread_cond_wait\fP
+\fBpthread_cond_signal\fP
+and \fBpthread_cond_broadcast\fP,
never return an error code.
.P
+The \fBpthread_cond_wait\fP function returns
+the following error codes on error:
+.RS
+.TP
+\fBEPERM\fP
+\fBmutex\fP is not locked.
+.RE
+.P
The \fBpthread_cond_timedwait\fP function returns
the following error codes on error:
.RS
.TP
+\fBEPERM\fP
+\fBmutex\fP is not locked.
+.TP
\fBETIMEDOUT\fP
The condition variable was not signaled
until the timeout specified by \fIabstime\fP.
[-- Attachment #3: wait2.c --]
[-- Type: text/plain, Size: 1081 bytes --]
/*
clang -o wait2 wait2.c -Wall -g;./wait2&p=$!;sleep 0.1;kill -USR1 $p;wait $p
[1] 3574450
signal
110=Connection timed out
[1]+ Exit 1 ./wait2
*/
#define _GNU_SOURCE
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
static void sig(int signo) {
puts("signal");
}
int main(void) {
setbuf(stdout,NULL);
struct sigaction sa;
memset(&sa,0,sizeof(sa));
sa.sa_handler=sig;
int err;
err=sigaction(SIGUSR1,&sa,NULL);
assert(!err);
// pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; // not reproducible
pthread_mutex_t mut = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
err=pthread_mutex_lock(&mut);
assert(!err);
struct timeval tv;
err=gettimeofday(&tv,NULL/*tz*/);
assert(!err);
struct timespec ts;
ts.tv_sec=tv.tv_sec;
ts.tv_nsec=tv.tv_usec*1000;
ts.tv_sec++;
err=pthread_cond_timedwait(&cond, &mut, &ts);
if (err) {
printf("%d=%s\n",err,strerror(err));
return 1;
}
return 0;
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal
2024-10-10 11:46 ` [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal Jan Kratochvil
@ 2024-10-10 12:25 ` Florian Weimer
2024-10-10 12:39 ` [patchv3] pthread_cond_wait and pthread_cond_timedwait can also return EPERM Jan Kratochvil
0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2024-10-10 12:25 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Alejandro Colomar, linux-man
* Jan Kratochvil:
> On Thu, 10 Oct 2024 18:32:51 +0800, Florian Weimer wrote:
>> * Jan Kratochvil:
>>
>> > +\fBEINTR\fP
>> > +\fBpthread_cond_wait\fP was interrupted by a signal.
>> > +.RE
>>
>> POSIX specifically disallows returning EINTR. Applications cannot
>> expect that pthread_cond_wait returns upon delivery of a signal. Such
>> a return is only possible due to the general allowance for spurious
>> wakeups, and must result in a zero result.
>
> OK, I agree when I tried that. So I have removed this part.
>
> But then I believe the EINTR presence at pthread_cond_timedwait documentation
> is also wrong (I did not change that in this patch) as I could not reproduce
> the EINTR (attached).
Indeed, POSIX disallows EINTR for all three wait functions.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [patchv3] pthread_cond_wait and pthread_cond_timedwait can also return EPERM
2024-10-10 12:25 ` Florian Weimer
@ 2024-10-10 12:39 ` Jan Kratochvil
2024-11-01 13:10 ` Alejandro Colomar
0 siblings, 1 reply; 7+ messages in thread
From: Jan Kratochvil @ 2024-10-10 12:39 UTC (permalink / raw)
To: Florian Weimer; +Cc: Alejandro Colomar, linux-man
[-- Attachment #1: Type: text/plain, Size: 236 bytes --]
On Thu, 10 Oct 2024 20:25:56 +0800, Florian Weimer wrote:
> Indeed, POSIX disallows EINTR for all three wait functions.
Fixed.
Jan
Signed-off-by: Jan Kratochvil <jan@jankratochvil.net>
Reviewed-by: Florian Weimer <fw@deneb.enyo.de>
[-- Attachment #2: pthread_cond_init.3.patch --]
[-- Type: text/plain, Size: 1018 bytes --]
diff --git a/man/man3/pthread_cond_init.3 b/man/man3/pthread_cond_init.3
index 42e7eac..df1f631 100644
--- a/man/man3/pthread_cond_init.3
+++ b/man/man3/pthread_cond_init.3
@@ -141,22 +141,28 @@ and a non-zero error code on error.
.
.SH ERRORS
\fBpthread_cond_init\fP,
-\fBpthread_cond_signal\fP,
-\fBpthread_cond_broadcast\fP,
-and \fBpthread_cond_wait\fP
+\fBpthread_cond_signal\fP
+and \fBpthread_cond_broadcast\fP,
never return an error code.
.P
+The \fBpthread_cond_wait\fP function returns
+the following error codes on error:
+.RS
+.TP
+\fBEPERM\fP
+\fBmutex\fP is not locked.
+.RE
+.P
The \fBpthread_cond_timedwait\fP function returns
the following error codes on error:
.RS
.TP
+\fBEPERM\fP
+\fBmutex\fP is not locked.
+.TP
\fBETIMEDOUT\fP
The condition variable was not signaled
until the timeout specified by \fIabstime\fP.
-.TP
-\fBEINTR\fP
-\fBpthread_cond_timedwait\fP was interrupted by a signal.
-.RE
.P
The \fBpthread_cond_destroy\fP function returns
the following error code on error:
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patchv3] pthread_cond_wait and pthread_cond_timedwait can also return EPERM
2024-10-10 12:39 ` [patchv3] pthread_cond_wait and pthread_cond_timedwait can also return EPERM Jan Kratochvil
@ 2024-11-01 13:10 ` Alejandro Colomar
2024-11-01 13:16 ` Alejandro Colomar
0 siblings, 1 reply; 7+ messages in thread
From: Alejandro Colomar @ 2024-11-01 13:10 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Florian Weimer, linux-man
[-- Attachment #1: Type: text/plain, Size: 1591 bytes --]
Hi Jan,
On Thu, Oct 10, 2024 at 08:39:20PM +0800, Jan Kratochvil wrote:
> On Thu, 10 Oct 2024 20:25:56 +0800, Florian Weimer wrote:
> > Indeed, POSIX disallows EINTR for all three wait functions.
>
> Fixed.
>
>
> Jan
>
> Signed-off-by: Jan Kratochvil <jan@jankratochvil.net>
> Reviewed-by: Florian Weimer <fw@deneb.enyo.de>
Patch applied. Thank you both!
Have a lovely day!
Alex
> diff --git a/man/man3/pthread_cond_init.3 b/man/man3/pthread_cond_init.3
> index 42e7eac..df1f631 100644
> --- a/man/man3/pthread_cond_init.3
> +++ b/man/man3/pthread_cond_init.3
> @@ -141,22 +141,28 @@ and a non-zero error code on error.
> .
> .SH ERRORS
> \fBpthread_cond_init\fP,
> -\fBpthread_cond_signal\fP,
> -\fBpthread_cond_broadcast\fP,
> -and \fBpthread_cond_wait\fP
> +\fBpthread_cond_signal\fP
> +and \fBpthread_cond_broadcast\fP,
> never return an error code.
> .P
> +The \fBpthread_cond_wait\fP function returns
> +the following error codes on error:
> +.RS
> +.TP
> +\fBEPERM\fP
> +\fBmutex\fP is not locked.
> +.RE
> +.P
> The \fBpthread_cond_timedwait\fP function returns
> the following error codes on error:
> .RS
> .TP
> +\fBEPERM\fP
> +\fBmutex\fP is not locked.
> +.TP
> \fBETIMEDOUT\fP
> The condition variable was not signaled
> until the timeout specified by \fIabstime\fP.
> -.TP
> -\fBEINTR\fP
> -\fBpthread_cond_timedwait\fP was interrupted by a signal.
> -.RE
> .P
> The \fBpthread_cond_destroy\fP function returns
> the following error code on error:
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patchv3] pthread_cond_wait and pthread_cond_timedwait can also return EPERM
2024-11-01 13:10 ` Alejandro Colomar
@ 2024-11-01 13:16 ` Alejandro Colomar
0 siblings, 0 replies; 7+ messages in thread
From: Alejandro Colomar @ 2024-11-01 13:16 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Florian Weimer, linux-man
[-- Attachment #1: Type: text/plain, Size: 2064 bytes --]
Hi Jan, Florian,
On Fri, Nov 01, 2024 at 02:10:16PM +0100, Alejandro Colomar wrote:
> Hi Jan,
>
> On Thu, Oct 10, 2024 at 08:39:20PM +0800, Jan Kratochvil wrote:
> > On Thu, 10 Oct 2024 20:25:56 +0800, Florian Weimer wrote:
> > > Indeed, POSIX disallows EINTR for all three wait functions.
> >
> > Fixed.
> >
> >
> > Jan
> >
> > Signed-off-by: Jan Kratochvil <jan@jankratochvil.net>
> > Reviewed-by: Florian Weimer <fw@deneb.enyo.de>
>
> Patch applied. Thank you both!
Sorry, no; I've removed the patch. It does two things, but I prefer if
you send two patches, each of which changes one thing, and please
provide a more detailed commit message. Thanks.
Cheers,
Alex
>
> Have a lovely day!
> Alex
>
> > diff --git a/man/man3/pthread_cond_init.3 b/man/man3/pthread_cond_init.3
> > index 42e7eac..df1f631 100644
> > --- a/man/man3/pthread_cond_init.3
> > +++ b/man/man3/pthread_cond_init.3
> > @@ -141,22 +141,28 @@ and a non-zero error code on error.
> > .
> > .SH ERRORS
> > \fBpthread_cond_init\fP,
> > -\fBpthread_cond_signal\fP,
> > -\fBpthread_cond_broadcast\fP,
> > -and \fBpthread_cond_wait\fP
> > +\fBpthread_cond_signal\fP
> > +and \fBpthread_cond_broadcast\fP,
> > never return an error code.
> > .P
> > +The \fBpthread_cond_wait\fP function returns
> > +the following error codes on error:
> > +.RS
> > +.TP
> > +\fBEPERM\fP
> > +\fBmutex\fP is not locked.
> > +.RE
> > +.P
> > The \fBpthread_cond_timedwait\fP function returns
> > the following error codes on error:
> > .RS
> > .TP
> > +\fBEPERM\fP
> > +\fBmutex\fP is not locked.
> > +.TP
> > \fBETIMEDOUT\fP
> > The condition variable was not signaled
> > until the timeout specified by \fIabstime\fP.
> > -.TP
> > -\fBEINTR\fP
> > -\fBpthread_cond_timedwait\fP was interrupted by a signal.
> > -.RE
> > .P
> > The \fBpthread_cond_destroy\fP function returns
> > the following error code on error:
>
>
> --
> <https://www.alejandro-colomar.es/>
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-11-01 13:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09 12:53 [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERM Jan Kratochvil
2024-10-10 10:32 ` Florian Weimer
2024-10-10 11:46 ` [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal Jan Kratochvil
2024-10-10 12:25 ` Florian Weimer
2024-10-10 12:39 ` [patchv3] pthread_cond_wait and pthread_cond_timedwait can also return EPERM Jan Kratochvil
2024-11-01 13:10 ` Alejandro Colomar
2024-11-01 13:16 ` Alejandro Colomar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox