<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>"cross posting", guilty.<BR><BR>
(This <EM>might </EM>have <EM>something </EM>to do with NT386GNU CM3 hanging upon startup but I haven't figured out much..in CM3, nanosleep fails and I don't think ThreadPThread__SignalHandler is ever called, whereas here nanosleep succeeds and the signal handler is called at least a few times; I'm going to try some hack with the Cygwin nanosleep uses sleep instead or something...)<BR><BR><BR><BR><BR>
<BLOCKQUOTE>
<HR id=EC_stopSpelling>
From: jayk123@hotmail.com<BR>To: cygwin@cygwin.com<BR>Subject: nanosleep messes up signals?<BR>Date: Sun, 10 Feb 2008 09:25:35 +0000<BR><BR>
<META content="Microsoft SafeHTML" name=Generator>
<STYLE>
.ExternalClass .EC_hmmessage P
{padding:0px;}
.ExternalClass EC_body.hmmessage
{font-size:10pt;font-family:Tahoma;}
</STYLE>
I'm no expert in pthreads, signals, sleep, etc., but..does this program not demonstrate incorrect behavior?<BR>If you run it as shown, a few signals get delivered, and then they stop.<BR>If you switch the #if 0, they get steadily delivered.<BR> <BR> <BR>#include <windows.h><BR>#include <pthread.h><BR>#include <stdio.h><BR>#include <signal.h><BR><BR>void*<BR>ThreadMain(<BR> void* p<BR> )<BR>{<BR> struct timespec a = { 1, 1 };<BR> struct timespec b = { 1, 1 };<BR> printf("in thread %x\n", GetCurrentThreadId());<BR> while (1)<BR> {<BR> printf("thread %x\n", GetCurrentThreadId());<BR> nanosleep(&a, &b);<BR> //sleep(0);<BR> Sleep(100);<BR> }<BR> return 0;<BR>}<BR><BR>void<BR>SignalHandler(<BR> int sig,<BR> siginfo_t * a,<BR> void* b<BR> )<BR>{<BR> printf("in SignalHandler %x thread %x\n", sig, GetCurrentThreadId());<BR>}<BR><BR>int main()<BR>{<BR> struct timespec a = { 1, 1 };<BR> struct timespec b = { 1, 1 };<BR> int NotMagic = 0; /* avoid an access violation */<BR> pthread_attr_t attr = { (void*) &NotMagic };<BR> pthread_t thr = { (void*) &NotMagic };<BR> struct sigaction act = { 0 };<BR> struct sigaction oldact = { 0 };<BR><BR> printf("main thread %x\n", GetCurrentThreadId());<BR><BR> act.sa_flags = (SA_RESTART | SA_SIGINFO);<BR> act.sa_sigaction = SignalHandler;<BR> sigaction(SIGUSR2, &act, &oldact);<BR><BR> pthread_attr_init (&attr);<BR> pthread_create(&thr, 0, ThreadMain, 0);<BR><BR> while(1)<BR> {<BR>#if 0<BR> sleep(1);<BR>#else<BR> printf("%d\n", nanosleep(&a, &b));<BR>#endif<BR> pthread_kill(thr, SIGUSR2);<BR> pthread_kill(thr, SIGUSR2);<BR> }<BR> return 0;<BR>}<BR><BR><BR><BR><BR><BR><BR>
<HR>
Climb to the top of the charts! Play the word scramble challenge with star power. <A href="http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan" target=_blank>Play now!</A> </BLOCKQUOTE><br /><hr />Helping your favorite cause is as easy as instant messaging. You IM, we give. <a href='http://im.live.com/Messenger/IM/Home/?source=text_hotmail_join' target='_new'>Learn more.</a></body>
</html>