Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 275431 Details for
Bug 408321
Process control signals cause pthread_cond_timedwait to return ETIMEDOUT
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
Test program for pthread_cond_timedwait usage when signal arrives
pthread_cond_timedwait_test.c (text/plain), 4.42 KB, created by
David Holmes
on 2007-12-03 06:20:32 UTC
(
hide
)
Description:
Test program for pthread_cond_timedwait usage when signal arrives
Filename:
MIME Type:
Creator:
David Holmes
Created:
2007-12-03 06:20:32 UTC
Size:
4.42 KB
patch
obsolete
>#include <stdio.h> >#include <unistd.h> >#include <pthread.h> >#include <time.h> >#include <errno.h> >#include <string.h> >#include <signal.h> > >/* This is a simple test to see if a pthread_cond_timedwait is > incorrectly terminated when process control signals, and others, are > sent to the process ie SIGTSTP and SIGCONT. We have observed > cases where the wait returns with ETIMEDOUT. > We install a signal handler for SIGUSR1 and SIGRTMIN >*/ > >static void my_handler(int sig, siginfo_t *sip, void *uvp) { > printf("Received signal %d\n", sig); >} > >int main (int argc, char* argv[]) { > > int status; > > clock_t clock = (argc > 1) ? CLOCK_REALTIME : CLOCK_MONOTONIC; > char* clock_name = (argc > 1) ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC"; > > // first initialize the pthread_cond_t to use the desired clock > > pthread_condattr_t attr; > pthread_cond_t cv; > > if ((status = pthread_condattr_init(&attr)) != 0) { > printf("pthread_condattr_init: %s", strerror(status)); > return -1; > } > > if ((status = pthread_condattr_setclock(&attr, clock)) != 0) { > if (status == EINVAL) > printf("Clock %s requested for pthread_cond_t is not supported\n", clock_name); > else { > printf("pthread_condattr_setclock: %s\n", strerror(status)); > return -1; > } > } > > > if ((status = pthread_cond_init(&cv, &attr)) != 0) { > printf("pthread_cond_init: %s\n", strerror(status)); > return -1; > > } > if ((status = pthread_condattr_destroy(&attr)) != 0) { > printf("pthread_condattr_destroy: %s\n", strerror(status)); > return -1; > } > > // now initialize the mutex > > pthread_mutex_t mutex; > > pthread_mutexattr_t mattr; > if ((status = pthread_mutexattr_init(&mattr)) != 0) { > printf("pthread_mutexattr_init: %s\n", strerror(status)); > return -1; > } >#if 0 > if ((status = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT)) != 0) { > if (status == ENOTSUP) > printf("Priority-inheritance is not supported for mutexes\n"); > else { > printf("pthread_mutexattr_setprotocol: %s\n", strerror(status)); > return -1; > } > } >#endif > if ((status = pthread_mutex_init(&mutex, &mattr)) != 0) { > printf("pthread_mutex_init: %s\n", strerror(status)); > return -1; > } > if ((status = pthread_mutexattr_destroy(&mattr)) != 0) { > printf("pthread_mutexattr_destroy: %s\n", strerror(status)); > return -1; > } > > // install signal handler for the RT signal and SIGUSR1 > > sigset_t mask_sigs; > struct sigaction sigact; > > sigfillset(&mask_sigs); > sigact.sa_sigaction = my_handler; > sigact.sa_mask = mask_sigs; > sigact.sa_flags = SA_SIGINFO; > > if(sigaction(SIGUSR1,&sigact,NULL) == -1) { > printf("sigaction() failed for SIGUSR1: %s", strerror(errno)); > return -1; > } > > if(sigaction(SIGRTMIN,&sigact,NULL) == -1) { > printf("sigaction() failed for SIGRTMIN: %s", strerror(errno)); > return -1; > } > > sigemptyset(&mask_sigs); > sigaddset(&mask_sigs,SIGUSR1); > sigaddset(&mask_sigs,SIGRTMIN); > if ((status = pthread_sigmask(SIG_UNBLOCK,&mask_sigs,NULL)) != 0) { > printf("pthread_sigmask: %s\n", strerror(status)); > return -1; > } > > > // now do the wait; > > status = pthread_mutex_lock(&mutex); > if (status != 0) { > printf("pthread_mutex_lock: %s\n", strerror(status)); > return -1; > } > > int timeout = 60; > struct timespec start; > struct timespec end; > struct timespec expected; > clock_gettime(clock, &start); > expected.tv_sec = start.tv_sec + timeout; > expected.tv_nsec = start.tv_nsec; > > volatile int done = 0; > > while (!done) { > > printf("Thread about to do %d sec pthread_cond_timedwait - send signals\n", timeout); > > status = pthread_cond_timedwait(&cv, &mutex, &expected); > clock_gettime(clock, &end); > > if (status == EINTR) { > printf("Broken linux: pthread_cond_wait returned EINTR\n"); > return -1 ; > } > if (status == ETIMEDOUT) { > int elapsed = end.tv_sec - start.tv_sec; > int n_elapsed = end.tv_nsec - start.tv_nsec; > if (n_elapsed < 0) > n_elapsed += 1000000000; > if (elapsed < timeout) { > printf("Error: pthread_cond_wait returned early: %d secs, %d nsecs\n", > elapsed, n_elapsed ); > return -1 ; > } > else { > printf("Returned ok\n"); > return 0; > } > } > if (status == ETIME) { > printf("Broken linux: pthread_cond_wait returned ETIME\n"); > return -1 ; > } > if (status != 0) { > printf("pthread_cond_timedwait: %s\n", strerror(status)); > return -1; > } > else { > printf("spurious wakeup ?\n"); > } > } > > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 408321
: 275431 |
278331