On Mon, Sep 23, 2019 at 11:33:41AM +0200, Johannes Berg wrote: > On Mon, 2019-09-23 at 10:25 +0100, Stefan Hajnoczi wrote: > Note, I'm not happy with this code at all, it deadlocks all the time. > Unfortunately I haven't really been able to figure out how to make glib > do what I wanted. > > The first issue is that sometimes glib actually seems to reports an FD > as readable when it's not, so I even put them into non-blocking mode :( Strange. Spurious wakeups are possible in general. I think when using fd monitoring (select(), poll(), etc) the fds should be in non-blocking mode. But if you're seeing this often it makes me wonder if something else is unintentionally reading available bytes... > The second is that I can't seem to understand how to do recursive > mainloops. > > To really do this *well*, it should remain a single-threaded > application, but would need a hook like > > run_mainloop_until_fd_readable(vdev->call_fd) > > inside the libvhost-user.c code, and that's a bit ugly ... if I even > could figure out how to implement that in glib. Recursive mainloops are tricky since usually event loop code isn't written to be re-entrant. It opens up a whole new dimension that existing code usually wasn't designed for. In this case you are writing the code from scratch so maybe you can get it to work, but it makes me wonder why the recursive mainloop is necessary. Stefan