[M3devel] FW: nanosleep messes up signals?

Jay jayk123 at hotmail.com
Sun Feb 10 10:28:22 CET 2008


"cross posting", guilty.
(This might have something 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...)


From: jayk123 at hotmail.comTo: cygwin at cygwin.comSubject: nanosleep messes up signals?Date: Sun, 10 Feb 2008 09:25:35 +0000


I'm no expert in pthreads, signals, sleep, etc., but..does this program not demonstrate incorrect behavior?If you run it as shown, a few signals get delivered, and then they stop.If you switch the #if 0, they get steadily delivered.  #include <windows.h>#include <pthread.h>#include <stdio.h>#include <signal.h>void*ThreadMain(    void* p    ){    struct timespec a = { 1, 1 };    struct timespec b = { 1, 1 };    printf("in thread %x\n", GetCurrentThreadId());    while (1)    {        printf("thread %x\n", GetCurrentThreadId());        nanosleep(&a, &b);        //sleep(0);        Sleep(100);    }    return 0;}voidSignalHandler(    int sig,    siginfo_t * a,    void* b    ){    printf("in SignalHandler %x thread %x\n", sig, GetCurrentThreadId());}int main(){    struct timespec a = { 1, 1 };    struct timespec b = { 1, 1 };    int NotMagic = 0; /* avoid an access violation */    pthread_attr_t attr = { (void*) &NotMagic };    pthread_t thr = { (void*) &NotMagic };    struct sigaction act = { 0 };    struct sigaction oldact = { 0 };    printf("main thread %x\n", GetCurrentThreadId());    act.sa_flags = (SA_RESTART | SA_SIGINFO);    act.sa_sigaction = SignalHandler;    sigaction(SIGUSR2, &act, &oldact);    pthread_attr_init (&attr);    pthread_create(&thr, 0, ThreadMain, 0);    while(1)    {#if 0        sleep(1);#else        printf("%d\n", nanosleep(&a, &b));#endif        pthread_kill(thr, SIGUSR2);        pthread_kill(thr, SIGUSR2);    }    return 0;}

Climb to the top of the charts! Play the word scramble challenge with star power. Play now! 
_________________________________________________________________
Helping your favorite cause is as easy as instant messaging. You IM, we give.
http://im.live.com/Messenger/IM/Home/?source=text_hotmail_join
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080210/2a5c853f/attachment-0001.html>


More information about the M3devel mailing list