delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/08/24/20:13:40

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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
X-T2-Posting-ID: dCnToGxhL58ot4EWY8b+QGwMembwLoz1X2yB7MdtIiA=
Date: Thu, 25 Aug 2005 02:13:23 +0200
From: Samuel Thibault <samuel DOT thibault AT ens-lyon DOT org>
To: cygwin AT cygwin DOT com
Subject: Re: threads and signals
Message-ID: <20050825001323.GC23620@bouh.ens-lyon.fr>
Mail-Followup-To: Samuel Thibault <samuel DOT thibault AT ens-lyon DOT org>, cygwin AT cygwin DOT com
Mime-Version: 1.0
User-Agent: Mutt/1.5.9i-nntp

--s2ZSL+KKDSLx8OML
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Christopher Faylor, le Wed 24 Aug 2005 00:49:55 -0400, a écrit :
> On Tue, Aug 23, 2005 at 10:51:44PM +0200, Samuel Thibault wrote:
> >The attached program doesn't work as expected: if I run it and try to
> >kill it (-15), nothing seem happens.  I if comment out
> >pthread_sigmask(), it does work as expected: the handler is called, and
> >threads are interrupted.  What's more: if I move pthread_sigmask()
> >after the pause() call in the foo() function, killing works twice, but
> >no more.
> 
> This should be fixed in the latest snapshot.  Or at least, it seems to
> now properly emulate linux.

Hmm, that's better indeed. But the signal handler is executed in the
wrong thread: the attached program outputs:

thread 0x4601c0
main 0x460008
thread 0x4601c0 awaken
thread 0x4601c0 awaken
thread 0x4601c0 awaken
thread 0x4601c0 awaken
thread 0x4601c0 awaken
thread 0x4601c0 awaken
thread 0x4601c0 awaken
foo 15 0x460008
main awaken

While the main thread asked the signal to be blocked. (It works as
expected on linux 2.6).

Regards,
Samuel

--s2ZSL+KKDSLx8OML
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="testt.c"

#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <pthread.h>

void *foo(void *bar) {
	fprintf(stderr,"thread %p\n",pthread_self());
	sigset_t blocked;
	sigemptyset(&blocked);
	sigaddset(&blocked,SIGTERM);
	pthread_sigmask(SIG_BLOCK, &blocked,NULL);
	while(1) {
		pause();
		fprintf(stderr,"thread %p awaken\n",pthread_self());
	}
}
void handler(int foo) {
	fprintf(stderr,"foo %d %p\n",foo, pthread_self());
}

void setsig(int foo) {
	struct sigaction action;
	memset(&action, 0, sizeof(action));
	sigemptyset(&action.sa_mask);
	action.sa_handler = handler;
	if (sigaction(foo,&action, NULL) == -1)
		perror("sigaction");
}

int main(int argc, char *argv[] ) {
	pthread_t t;
	setsig(SIGTERM);
	pthread_create(&t, NULL, foo, NULL);
	fprintf(stderr,"main %p\n", pthread_self());
	while(1) {
		pause();
		fprintf(stderr,"main awaken\n");
	}
}


--s2ZSL+KKDSLx8OML
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019