[Spice-devel] [PATCH v4 7/8] vdagent: Use GMainLoop

Christophe Fergeau cfergeau at redhat.com
Tue Oct 17 07:56:56 UTC 2017


On Mon, Oct 16, 2017 at 10:53:43AM -0400, Frediano Ziglio wrote:
> > -
> > -        n = select(nfds, &readfds, &writefds, NULL, NULL);
> > -        if (n == -1) {
> > -            if (errno == EINTR)
> > -                continue;
> > -            syslog(LOG_ERR, "Fatal error select: %s", strerror(errno));
> > -            break;
> > -        }
> > +    if (vdagent_init_async_cb(agent) == G_SOURCE_CONTINUE)
> > +        agent->timer_source_id = g_timeout_add_seconds(1,
> > vdagent_init_async_cb, agent);
> 
> Was thinking about this code.
> Maybe would be better to just register the function with
> 
>     agent->timer_source_id = g_timeout_add_seconds(0, vdagent_init_async_cb, agent);

If your expectations are that g_timeout_add_seconds(0, ...) is going to
trigger the callback right away, this is not necessarily going to work
as expected, see the last paragraph of
https://cgit.freedesktop.org/spice/spice-gtk/commit/?id=3e3b37b672

« update_display_timer(0) schedules a timeout to be run with
g_timeout_add_seconds(0). However, g_timeout_add_seconds() schedules
timers with a granularity of a second, so the timeout we scheduled with
g_timeout_add_seconds() may fire up to 1 second later than when we
called it, while we really wanted it to fire as soon as possible.
Special-casing update_display_timer(0) and using g_timeout_add() in that
case avoid this issue. In theory, the race could probably still happen
with a very very bad timing, but in practice I don't think it will be
possible to trigger it after this change. »

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20171017/374625d1/attachment.sig>


More information about the Spice-devel mailing list