[Python-Dev] Signals, threads, blocking C functions

Adam Olsen rhamph at gmail.com
Wed Sep 13 01:03:54 CEST 2006

On 9/12/06, Gustavo Carneiro <gjcarneiro at gmail.com> wrote:
> On 9/12/06, Adam Olsen <rhamph at gmail.com> wrote:
> > My previous mention of using a *single* flag may survive corruption
> > simply because we can tolerate false positives.  Signal handlers would
> > write 0xFFFFFFFF, the poll loop would check if *any* bit is set.  If
> > so, write 0x0, read off the fd, then loop around and check it again.
> > If the start of the read() acts as a write-barrier it SHOULD guarantee
> > we don't miss any positive writes.

> PyErr_CheckSignals()
> {
>   if (signal_flag) {
>      char signum;
>      signal_flag = 0;
>      while (read(signal_pipe_r, &signum, 1) == 1)
>          process_signal(signum);
>   }
> }

The more I think about this the less I like relying on read() imposing
a hardware write barrier.  Unless somebody can say otherwise, I think
we'd be better of putting dummy
PyThread_aquire_lock/PyThread_release_lock calls in there.

Adam Olsen, aka Rhamphoryncus

More information about the Python-Dev mailing list