----- Original Message ----- > From: [email protected] > To: "Jan Stancek" <[email protected]> > Cc: [email protected] > Sent: Tuesday, 13 August, 2013 5:13:57 PM > Subject: Re: [LTP] [PATCH v4 2/2] open_posix_testsuite/../mq_timedsend/12-1: > fix race > > > /* > > * This handler is just used to catch the signal and stop sleep (so the > > @@ -59,12 +59,10 @@ int errno_eintr; > > */ > > void justreturn_handler(int signo) > > { > > - /* Indicate that the signal handler was called */ > > - in_handler = 1; > > - return; > > + in_handler++; > > } > > > > -void *a_thread_func() > > +void *a_thread_func(void *arg) > > { > > int i, ret; > > struct sigaction act; > > @@ -86,101 +84,111 @@ void *a_thread_func() > > attr.mq_maxmsg = MAXMSG; > > attr.mq_msgsize = BUFFER; > > gqueue = mq_open(gqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); > > - if (gqueue == (mqd_t) - 1) { > > - perror("mq_open() did not return success"); > > - pthread_exit((void *)PTS_UNRESOLVED); > > - return NULL; > > - } > > + if (gqueue == (mqd_t) -1) > > + error_and_exit(errno, "mq_open"); > > > > - /* mq_timedsend will block for 10 seconds when it waits */ > > - ts.tv_sec = time(NULL) + 10; > > + /* mq_timedsend will block for TIMEOUT seconds when it waits */ > > + ts.tv_sec = time(NULL) + TIMEOUT; > > ts.tv_nsec = 0; > > > > - /* Tell main it can go ahead and start sending SIGUSR1 signal */ > > - sem = INMAIN; > > + /* main can now start sending SIGUSR1 signal */ > > + ret = pthread_barrier_wait(&barrier); > > + if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) > > + error_and_exit(ret, "pthread_barrier_wait start"); > > > > for (i = 0; i < MAXMSG + 1; i++) { > > ret = mq_timedsend(gqueue, msgptr, strlen(msgptr), 1, &ts); > > - if (ret != -1) > > - continue; > > - > > - if (errno == EINTR) { > > - if (mq_unlink(gqname) != 0) { > > - perror("mq_unlink() did not return success"); > > - pthread_exit((void *)PTS_UNRESOLVED); > > - return NULL; > > - } > > - printf("thread: mq_timedsend interrupted by signal" > > - " and correctly set errno to EINTR\n"); > > - errno_eintr = 1; > > - pthread_exit((void *)PTS_PASS); > > - return NULL; > > - } else { > > - printf("mq_timedsend not interrupted by signal or" > > - " set errno to incorrect code: %d\n", errno); > > - pthread_exit((void *)PTS_FAIL); > > - return NULL; > > + if (ret == -1) { > > + mq_timedsend_errno = errno; > > + break; > > } > > } > > > > - /* Tell main that it the thread did not block like it should have */ > > - sem = INTHREAD; > > + if (mq_unlink(gqname) != 0) > > + error_and_exit(errno, "mq_unlink"); > > + > > + switch (mq_timedsend_errno) { > > + case -1: > > + mq_timedsend_errno = 0; > > + printf("Error: mq_timedsend wasn't interrupted\n"); > > + break; > > + case EINTR: > > + printf("thread: mq_timedsend interrupted by signal" > > + " and correctly set errno to EINTR\n"); > > + break; > > + default: > > + printf("mq_timedsend not interrupted by signal or" > > + " set errno to incorrect code: %d\n", > > + mq_timedsend_errno); > > + break; > > + } > > + > > + /* wait until main stops sending signals */ > > + ret = pthread_barrier_wait(&barrier); > > + if (ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD) > > + error_and_exit(ret, "pthread_barrier_wait end"); > > > > - perror("Error: thread never blocked\n"); > > - pthread_exit((void *)PTS_FAIL); > > - return NULL; > > + if (mq_timedsend_errno == EINTR) > > + pthread_exit((void *)PTS_PASS); > > + else > > + pthread_exit((void *)PTS_FAIL); > > Are these even used? The pthread_join() below has NULL parameter and the > mq_timedsend_errno is used directly.
I didn't notice that. You're right I think we can remove it. > The rests looks OK. Thanks for review, Jan > > -- > Cyril Hrubis > [email protected] > ------------------------------------------------------------------------------ Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
