help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] non-blocking pipe read issue


From: Derek Zhou
Subject: Re: [Help-smalltalk] non-blocking pipe read issue
Date: Thu, 2 Feb 2012 17:59:30 -0800
User-agent: Mutt/1.5.20 (2009-06-14)

On Thu, Feb 02, 2012 at 01:39:41PM +0100, Paolo Bonzini wrote:
> On 02/02/2012 01:02 PM, Derek Zhou wrote:
> >RETSIGTYPE
> >file_polling_handler (int sig)
> >{
> >   if (num_used_pollfds>  0)
> >     {
> >       _gst_disable_interrupts (true);
> >       _gst_async_call (async_signal_polled_files, NULL);
> >       _gst_enable_interrupts (true);
> >     }
> >
> >   _gst_set_signal_handler (sig, file_polling_handler);
> >   _gst_wakeup ();
> >}
> >
> >...
> >   set_file_interrupt (fd, file_polling_handler);
> >
> >   /* Now check if I/O was made possible while setting up our machinery...
> >      If so, exit; otherwise, wait on the semaphore and the SIGIO
> >      will wake us up.  */
> >
> >   result = _gst_sync_file_polling (fd, cond);
> >   if (result == 0)
> >     {
> >       if (!head)
> >         head = new;
> >       else
> >         *p_tail_next = new;
> >       p_tail_next =&new->next;
> >
> >       num_used_pollfds++;
> >       _gst_register_oop (semaphoreOOP);
> >       _gst_sync_wait (semaphoreOOP);
> >     }
> >   else
> >     xfree (new);
> >...
> >
> >Although it does a second poll after the sig handler setup trying to catch
> >this possibility, the data could still come in after the second poll but
> >before the _gst_sync_wait. The sig handler will trigger but it does not
> >prevent the process going to sleep.
> >
> > From the look of it the problem is not limited to pipes, the same could
> >happen to sockets as well.
> 
> Huh, the race is of course on setting num_used_pollfds.  Stupid me.
> Holger, can you give the attached patch a try?
> 
> Paolo
> 
This patch seems to fix my problem. Thanks. 

Derek



reply via email to

[Prev in Thread] Current Thread [Next in Thread]