After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 707699 - Frame clock tick callbacks should hold GDK lock?
Frame clock tick callbacks should hold GDK lock?
Status: RESOLVED INCOMPLETE
Product: gtk+
Classification: Platform
Component: Widget: Other
unspecified
Other Mac OS
: Normal major
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-09-07 19:59 UTC by Philip Chimento
Modified: 2014-01-25 02:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Hold GDK lock during frame clock tick callback (1008 bytes, patch)
2013-09-07 19:59 UTC, Philip Chimento
none Details | Review

Description Philip Chimento 2013-09-07 19:59:13 UTC
I've found one of my projects (www.chimara-if.org) to be broken in the 3.8 series of GTK on the Quartz backend. Admittedly, this project is a heavy user of gdk_threads_enter()/_leave(), and I really should port it so that GTK calls are on the main thread, but I can't invest that time in it just now. And though GDK threads are deprecated, they should still work until GTK 4, right?

Debugging shows that the program crashes early on, at various places, somewhere during drawing a GtkTextView. I've dealt with this kind of thing before and usually it meant that I forgot to acquire the GDK lock before calling a GTK function. Indeed, both the main thread and my thread were in the middle of calling GTK functions when the program crashed, suggesting a race condition. Only, my thread did hold the GDK lock, so I thought maybe GTK forgot to acquire it somewhere.

By bisection I determined that the regression started at some point during the introduction of frame clocks in the 3.7 series. I wondered if the GDK lock was held while running frame clock tick callbacks; it did not seem to be. This patch fixes that. However, it only fixes my crash for one revision of GTK, 449e8c88 (https://git.gnome.org/browse/gtk+/commit/?id=449e8c88565b444d1399a9080bde5141d054bde6), the following commit breaks it again -- which suggests that the race condition is elsewhere entirely and holding the GDK lock during tick callbacks merely prevents it from occurring by chance.

So even though it doesn't solve my problem I thought I would suggest this fix in a bug report, since it seems logical to me. However, I really don't know what repercussions it might have. Can anyone advise me?
Comment 1 Philip Chimento 2013-09-07 19:59:37 UTC
Created attachment 254359 [details] [review]
Hold GDK lock during frame clock tick callback
Comment 2 Benjamin Otte (Company) 2013-09-08 22:56:48 UTC
The frame clock uses gdk_threads_add_timeout_full(), and that one does the gdk_threads_enter/leave() dance. So as far as I can see, the lock should be always taken where your patch adds it.

In any case, the correct fix is making sure that the frame clock always takes the lock, so you'll need to do some more digging I'm afraid.