develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [PATCH] Adding callbacks to the core

Thread Previous | Thread Next
From:
David M. Lloyd
Date:
August 22, 2001 07:51
Subject:
Re: [PATCH] Adding callbacks to the core
Message ID:
Pine.LNX.4.33.0108220944010.1027-100000@homebody.freemm.org
On Wed, 22 Aug 2001, Dan Sugalski wrote:

> > > 1. If there is at least one callback waiting, process callbacks.
> > > 2. (for loop):
> > > 1. Put head in cur.
> > > 2. Check to make sure cur isn't NULL (in case callback went away)
> > > 3. Grab next item into next, so that next callback doesn't go away.
> > > 4. Call current callback; it can enable/disable whatever it wants
> > > without affecting anything crucial.
>
> I'm not sure this is safe. (I'm pretty sure there's something wrong
> with it, but I can't put my finger on it) Depending on ordering's a
> bad thing generally when dealing with async/threaded code, since many
> processors don't make many execution ordering guarantees, you may get
> interrupted in the middle of things if a signal or other interrupt
> occurs, the C compiler may reorder when optimizing, and threaded code
> can potentially be executing on multiple processors simultaneously.

I am anything but an expert on this sort of thing, but I figured I could
depend on ordering here because even if the CPU does odd things like
threading, the CPU still has to depend on the logical order of the
operations I'm performing; for instance no matter how the CPU threads, it
wouldn't make logical sense to do a comparison with a variable before or
during an assignment that precedes the comparision.

However, looking at this code yet again, I suspect there may be a race at
the beginning of the for loop.  I'll have to look at it some more.  Sigh.

> Not that a mutex is the way to go since last time I checked you can't
> do most pthread operations (including mutex ones) in a signal or other
> interrupt handler.

This loop is not run from within a signal/interrupt handler... it is
called from Perl_runops_*.

I may have to go to mutexes after all... :-(

- D

<dmlloyd@tds.net>


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About