This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Instability with signals and threads
- From: Mikulas Patocka <mikulas at artax dot karlin dot mff dot cuni dot cz>
- To: cygwin at cygwin dot com
- Date: Wed, 19 Nov 2014 18:28:47 +0100 (CET)
- Subject: Re: Instability with signals and threads
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1411191708220 dot 32609 at artax dot karlin dot mff dot cuni dot 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