[M3devel] FW: nanosleep messes up signals?

Jay jayk123 at hotmail.com
Sun Feb 10 10:43:58 CET 2008


oh the burden of my own cross-posting..
 
 - Jay


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


Given that sleep is implemented via nanosleep in the obvious simple way..Still, any additional clues/explanations are welcome. :) - Jay


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! 

Connect and share in new ways with Windows Live. Get it now! 
_________________________________________________________________
Climb to the top of the charts! Play the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20080210/40b111bc/attachment-0002.html>


More information about the M3devel mailing list