| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:date:from:to:subject:in-reply-to:message-id | |
| :references:mime-version:content-type; q=dns; s=default; b=JoPhs | |
| hDRUjVNw1fzi4bdLaSQ9B/TiVm1P9Ave/euLkTf71VPmYWjIOVVTj8nQjpDUJQ3W | |
| /u4meimtbYxAFACefWbvBZFXQMaUNP1gVZ5VS19D4f99iImuOQaK6hgBqvxqUiJQ | |
| oSXiU/QRCkcrPg1NW8Uyod6rqJ24MsixUWT354= | |
| DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:date:from:to:subject:in-reply-to:message-id | |
| :references:mime-version:content-type; s=default; bh=4motQGKP/j1 | |
| EqlP7Tc0iK1wIyx4=; b=mdjP3InCpUrHtU+pV/Gb1ppPhd/2pceiv/2yMVEVUQF | |
| 4TLNbVGbszuY+/KZdYfqxNb3dLgxyO7Xun7TKVYUxezNWBD1LdKn0HkIKD7nFuvc | |
| D+426Ux1apboALH8gN5bH9t7WYLU5tU66boH6niop5N77JZDH5GelDEbNA3ZAzfk | |
| = | |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| Authentication-Results: | sourceware.org; auth=none |
| X-Virus-Found: | No |
| X-Spam-SWARE-Status: | No, score=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 |
| X-HELO: | artax.karlin.mff.cuni.cz |
| Date: | Wed, 19 Nov 2014 18:28:47 +0100 (CET) |
| From: | Mikulas Patocka <mikulas AT artax DOT karlin DOT mff DOT cuni DOT cz> |
| To: | cygwin AT cygwin DOT com |
| Subject: | Re: Instability with signals and threads |
| In-Reply-To: | <alpine.DEB.2.02.1411191708220.32609@artax.karlin.mff.cuni.cz> |
| Message-ID: | <alpine.DEB.2.02.1411191820100.110638@artax.karlin.mff.cuni.cz> |
| References: | <alpine DOT DEB DOT 2 DOT 02 DOT 1411191708220 DOT 32609 AT artax DOT karlin DOT mff DOT cuni DOT cz> |
| User-Agent: | Alpine 2.02 (DEB 1266 2009-07-14) |
| X-Personality-Disorder: | Schizoid |
| MIME-Version: | 1.0 |
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |