0

I am fairly new to GDK/GTK but I'm trying to make some C code thread-safe. (It's quite large otherwise I would post it here.) I was doing some stress tests and GDB stopped with an error: program received signal SIGABRT, aborted. The program halted in a function called gdk_window_get_frame_clock, which according to the GDK documentation is a low level function for synchronizing screen repainting. The stack trace just shows me "0x0 in ??" for the caller. Does anyone know what is going on here or where I can start searching? I'm completely baffled.

Chris
  • 55
  • 8
  • Need a bit more information than this. Look at gdb's stack trace to find out what was happening in the bits of code you write when the problem happened, and start there. – Crowman Oct 06 '14 at 01:48
  • It is not possible to call GTK/GDK function directly from other thread. Are you properly locking all accesses from other threads by `gdk_threads_enter()`/`gdk_threads_leave()` or equivalent functions? – j123b567 Oct 06 '14 at 07:36
  • The application sets itself up by creating a new worker thread to do complex calculations during execution as well as repainting. The main thread handles user interactions. It's almost certainly a race condition. I'm using POSIX threads and mutex locks to control access to my application variables. I'll try setting up the critical sections and post back when I get a chance. – Chris Oct 13 '14 at 14:00

1 Answers1

0

Never draw anything from another thread than the thread containing the glib or gtk main loop. Use g_idle_add, g_timeout_add or custom hook based on GSource to enqueue UI changes from within a secondary thread (those are threadsafe!)

drahnr
  • 6,782
  • 5
  • 48
  • 75
  • Thanks! This worked. From what I can tell, GDK 2 allows the gdk_threads_enter/gdk_threads_leave method to lock GDK resources from separate threads. However, GDK 3 does not. Now I'm using g_idle_add to call a function to queue the main window redrawing. It is leading to excessive CPU usage but this is a good starting point. – Chris Nov 23 '14 at 00:02