public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
To: cygwin@cygwin.com
Subject: Re: Instability with signals and threads
Date: Wed, 19 Nov 2014 17:30:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.02.1411191820100.110638@artax.karlin.mff.cuni.cz> (raw)
In-Reply-To: <alpine.DEB.2.02.1411191708220.32609@artax.karlin.mff.cuni.cz>



On Wed, 19 Nov 2014, Mikulas Patocka wrote:

> Hi
> 
> I have a program that sets a repetitive timer with setitimer and spawns 
> several threads.
> 
> The program is very unstable on cygwin, it locks up in few minutes.

This is a simplified example that triggers the lockup very quicky.

When I change remove_tls so that it always acquires the lock, it reduces 
the probability of the lockup, but doesn't eliminate it entirely - so 
there must be some other bug.

Mikulas



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <pthread.h>

static volatile sig_atomic_t events;

static void signal_handler(int sig)
{
	events++;
}

static void *thread_func(void *ptr)
{
	return NULL;
}

#define N_THREADS	12

static pthread_t threads[N_THREADS];

int main(void)
{
	int i, r;
	struct sigaction sa;
	struct itimerval timer;

	memset(&sa, 0, sizeof sa);
	sa.sa_handler = signal_handler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags |= SA_RESTART;
	r = sigaction(SIGALRM, &sa, NULL);
	if (r) perror("sigaction"), exit(1);

	timer.it_interval.tv_sec = 0;
	timer.it_interval.tv_usec = 1000;
	timer.it_value = timer.it_interval;
	r = setitimer(ITIMER_REAL, &timer, NULL);
	if (r) perror("setitimer"), exit(1);

	while (1) {
		for (i = 0; i < N_THREADS; i++) {
			r = pthread_create(&threads[i], NULL, thread_func, NULL);
			if (r) fprintf(stderr, "pthread_create: %s", strerror(r));
		}
		for (i = 0; i < N_THREADS; i++) {
			r = pthread_join(threads[i], NULL);
			if (r) fprintf(stderr, "pthread_create: %s", strerror(r));
		}
		printf("events: %d\n", events);
	}
}

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2014-11-19 17:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-19 16:43 Mikulas Patocka
2014-11-19 17:30 ` Mikulas Patocka [this message]
2014-11-20 10:00 ` Corinna Vinschen
2014-11-20 16:22   ` Corinna Vinschen
2014-11-20 20:24 Mikulas Patocka
2014-11-21  4:24 ` Mikulas Patocka
2014-11-21 10:28 ` Corinna Vinschen
2014-11-21 10:38   ` Corinna Vinschen
2014-11-21 14:43 ` Mikulas Patocka
2014-11-21 14:46   ` Mikulas Patocka
2014-11-21 14:47   ` Corinna Vinschen
2014-11-21 16:30     ` Marco Atzeri
2014-11-21 16:37       ` Corinna Vinschen
2014-11-21 20:36         ` Yaakov Selkowitz
2014-11-21 20:44           ` Corinna Vinschen
2014-11-28 21:13             ` Yaakov Selkowitz
2014-11-28 22:35     ` Corinna Vinschen
2014-12-04  9:42       ` Corinna Vinschen

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=alpine.DEB.2.02.1411191820100.110638@artax.karlin.mff.cuni.cz \
    --to=mikulas@artax.karlin.mff.cuni.cz \
    --cc=cygwin@cygwin.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).