Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I have a program which is uses sigaction to register for a SIGIO signal (for incoming data on a fd) with an appropriate event handler. I also create a ...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Location
    India
    Posts
    5

    Thread scheduling and signalling

    Hi,
    I have a program which is uses sigaction to register for a SIGIO signal (for incoming data on a fd) with an appropriate event handler. I also create a new detached thread 'B' that does some work with the received data.


    Normally the thread B runs properly. But when my event handler is called (because a there is new incoming data), after the event is handled, the thread B is not called immediately. There is a noticeable delay of the order of many seconds before it is scheduled again .During this delay, my program is doing nothing.

    What am i doing wrong? Is there someway i can run thread B as soon as the event is handled (and assuming no other work is to be carried out)?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Without looking at the code in question, there isn't much we can say about this. Usually it is due to some sort of deadlock occuring.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Apr 2009
    Location
    India
    Posts
    5
    Hi,

    I've found that the problem is in my event handler. I'm using the handler to read SIGIO events to notify availability of incoming data.Inside the handler i sleep for a certain time.During that time, the same event is being generated again as new bytes are received.Consequently, after the handler returns, the handler is again called for all the pending signals.I'm sleeping inside the handler because the read can return a significant chunk of data rather than a byte or two.
    Code:
      void my_handler(int signo, siginfo_t *info, void *ignored)
      {       
              int n;        
              if (info->si_code == POLL_IN) { //Incoming data available
                         
                              if (myfd == info->si_fd) {
                                    
                                      /*I'm sleeping now because i want to read a whole chunk rather than indiviudal chars*/
                                      usleep(500000);//0.5 seconds
                                      ioctl(fd, FIONREAD, &n);//read no. of chars in available Rx buffer;
                                      n = read(myfd,buffer, n);
                                      if (n > 0)
                                              printf("got chunk of data")
                                      else
                                          printf("Just  a pening signal")
                                                                       
                                      return;
                              }                 
              }
      }
    Is there someway i can ignore all pending signals during the time my handler was executing? This must happen immediately after hander returns (to only ignore all backlog signals). If i ignore it sometime later, i risk loosing further notifications that occur when a new chunk of data arrives.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Why are you raising signals when data is available instead of using select() to see when data is available on the fd? Use of signals for this sort of purpose is very prone to all sorts of nasty race conditions and such. Also, sleeping inside a signal handler is just bad (unadvisable at least) practice.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...