From: Jan Kratochvil <jan@jankratochvil.net>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: Alejandro Colomar <alx@kernel.org>, linux-man@vger.kernel.org
Subject: Re: [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal
Date: Thu, 10 Oct 2024 19:46:18 +0800 [thread overview]
Message-ID: <Zwe-ipF5N82CTN64@host2.jankratochvil.net> (raw)
In-Reply-To: <8734l4fdt8.fsf@mid.deneb.enyo.de>
[-- 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;
}
next prev parent reply other threads:[~2024-10-10 11:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jan Kratochvil [this message]
2024-10-10 12:25 ` [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zwe-ipF5N82CTN64@host2.jankratochvil.net \
--to=jan@jankratochvil.net \
--cc=alx@kernel.org \
--cc=fw@deneb.enyo.de \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox