Re: [patch] pthread_cond_wait and pthread_cond_timedwait can also return EPERMignalignal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx>
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.
/*
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;
}

[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux