[Spice-devel] [spice-gtk] Fix IN_MAIN_CONTEXT when using coroutine=gthread

Christophe Fergeau cfergeau at redhat.com
Fri Nov 15 07:54:42 PST 2013


On Fri, Nov 15, 2013 at 10:45:42AM -0500, Marc-André Lureau wrote:
> 
> 
> ----- Original Message -----
> > On Fri, Nov 15, 2013 at 04:05:55PM +0100, Christophe Fergeau wrote:
> > > However, this is an
> > > implementation detail of the ucontext coroutine implementation, in the
> > > gthread implementation, coroutine_self()->caller will be non-NULL even in
> > > the main context.
> > NB: Maybe the actual bug is that coroutine_self()->caller in non-NULL for
> > the main context in the gthread backend, but I'm not familiar enough with
> > the coroutine code to know that.
> 
> I don't see when coroutine_self()->caller could be non-null in main coroutine, even with gthread backend.

This is coroutine_swap() from coroutine_gthread.c
void *coroutine_swap(struct coroutine *from, struct coroutine *to, void *arg)
{
        from->runnable = FALSE;

from is non-NULL here


        to->runnable = TRUE;

'to' becomes the coroutine with 'runnable' set to TRUE


        to->data = arg;
        to->caller = from;

we set to->caller to something non-NULL

        CO_DEBUG("BROADCAST");
        g_cond_broadcast(run_cond);
        CO_DEBUG("UNLOCK");
        g_mutex_unlock(run_lock);
        CO_DEBUG("LOCK");
        g_mutex_lock(run_lock);
        while (!from->runnable) {
                CO_DEBUG("WAIT");
                g_cond_wait(run_cond, run_lock);
        }

we get out of the loop when the coroutine that was woken up has 'runnable'
set to TRUE, this corresponds to the 'to' variable we looked at at the
beginning, which has a non-NULL 'caller'

        current = from;

and the current task (the one returned by coroutine_self() becomes 'from',
which has a non-NULL caller regardless of whether it's the main context or
another one.

> Do you think you could trace that? it could indicate a bigger problem.

Unless I missed something, this is consistent with the code is doing, so
I'm not exactly sure what I should be looking for.

Christophe


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20131115/57cf21e4/attachment.pgp>


More information about the Spice-devel mailing list