All of lore.kernel.org
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: Jan Stancek <jstancek@redhat.com>
Cc: ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH v4 2/2] open_posix_testsuite/../mq_timedsend/12-1: fix race
Date: Tue, 13 Aug 2013 17:13:57 +0200	[thread overview]
Message-ID: <20130813151357.GE29233@rei> (raw)
In-Reply-To: <364946f8001c14134ce7bf32fe8b5c6b5201bcfb.1376399706.git.jstancek@redhat.com>

>  /*
>   * 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.

The rests looks OK.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2013-08-13 15:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-24  6:39 [LTP] [PATCH 1/2] open_posix_testsuite/../mq_timedsend/12-1: fix long lines Jan Stancek
2013-07-24  6:39 ` [LTP] [PATCH 2/2] open_posix_testsuite/../mq_timedsend/12-1: fix race Jan Stancek
2013-07-25 10:07   ` [LTP] [PATCH v2 " Jan Stancek
2013-07-31 14:30     ` [LTP] [PATCH v3 " Jan Stancek
2013-08-12 14:43       ` chrubis
2013-08-13 13:38       ` [LTP] [PATCH v4 " Jan Stancek
2013-08-13 15:13         ` chrubis [this message]
2013-08-14 11:28         ` [LTP] [PATCH v5 " Jan Stancek
2013-08-15 12:53           ` chrubis
2013-08-27 11:51             ` chrubis
2013-07-30 17:35   ` [LTP] [PATCH " chrubis
     [not found]     ` <111760967.10033378.1375213746603.JavaMail.root@redhat.com>
2013-07-31 11:07       ` chrubis

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=20130813151357.GE29233@rei \
    --to=chrubis@suse.cz \
    --cc=jstancek@redhat.com \
    --cc=ltp-list@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.