[Top][All Lists]

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

Re: [Chicken-users] srfi-18 and callbacks

From: Jim Ursetto
Subject: Re: [Chicken-users] srfi-18 and callbacks
Date: Fri, 11 Apr 2008 21:37:34 -0600

On 4/11/08, felix winkelmann <address@hidden> wrote:
> On Sat, Apr 5, 2008 at 8:10 PM, Jim Ursetto <address@hidden> wrote:
> Uh oh... This is a case that should probably be avoided. I couldn't even
> say what exactly happens, but you will have to do some locking because
> the Scheme thread-context will be different when you return from the
> callback (as you have described above). When you say "thread 2 enters
> the callback" does that mean that a context switch occurs while the
> callback is executing?

Yes.  OK, that's what I thought.  I changed my approach completely (doesn't use
callbacks anymore) -- so everything is ok.  But I did realize in the meantime
that this could affect any multithreaded program using callbacks, as if a
context switch occurs during a callback then callback returns may occur out of
order.  (It could occur if one thread registered a GUI callback and one
registered a database callback--unless you somehow prevent context switches
within callbacks or arrange it externally so callbacks may never overlap).

For example, I think it is unsafe to use sqlite3:define-function or
sqlite3:define-collation if you have multiple threads, even using different
database connections, as the callbacks may overlap in time.

reply via email to

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