race condition without multiple threads?



Hi all,

am having this problem with a segfault that's been nagging me for days
appearing after some streamlining of completely unrelated code.

I have this function which repeatedly updates a label with some status
information like this:

   ...
   // set the text in the label to some value
   gtk_button_set_label(GTK_BUTTON(filename), file);

   // adjust the size of the button containing the label
   // first get the size of the text
   layout = gtk_widget_create_pango_layout(filename, file);
   pango_layout_get_pixel_size(layout, &width, &height);
   g_object_unref(layout);
   // FIXME: find out why this is needed and fix it!!!
   usleep(1);
   // then set the desired size
   // FIXME: also I wanted to add a maximum value for the width
   gtk_widget_set_size_request(GTK_WIDGET(filename), (width + 30), -1);
   ...

Now, if I remove the usleep (or any other line of code slowing things down,
like a printf) the thing crashes.

To me this looks like some sort of race condition. However, there is just a
single thread involved in updating the GUI. (there is another thread which
does some computation but never interferes with the GUI.)

I am using timeouts. What happens is:
- the main loop adds a timeout
- when the timeout gets set off, it triggers a function to take a screenshot
   - this also updates the label above and another led-like widget
   - then it adds another timeout and returns

The time between the timeouts does not seem to be relevant ... making
it 1 second does not fix the problem. Actually the backtrace seems to indicate that the code doesn't even get to do the timeout even once. -- Adding the single
ms between reading from the layout and changing it, however, does.

I tried adding thread-safety code by adding the g_thread_init call before any
other GTK/GDK code, putting g_threads_enter/leave around gtk_main() and
around the body of the function triggered by the timeout ... to no betterment.



Could anybody shed some light on whether it's smth. I should have been
expecting because I'm missing smth. really obvious, or what I can do to fix
this?


TIA,

Karl.



P.S.:

#0  0x405065f0 in strcmp () from /lib/libc.so.6
#1  0x403592a2 in g_param_values_cmp () from /usr/lib/libgobject-2.0.so.0
#2  0x4039e0ed in g_hash_table_lookup () from /usr/lib/libglib-2.0.so.0
#3 0x4035981d in g_param_spec_pool_lookup () from /usr/lib/libgobject-2.0.so.0
#4  0x40353c6b in g_object_notify () from /usr/lib/libgobject-2.0.so.0
#5 0x4019b90e in gtk_widget_set_uposition () from /usr/lib/libgtk-x11-2.0.so.0 #6 0x4019baa0 in gtk_widget_set_size_request () from /usr/lib/libgtk-x11-2.0.so.0
#7  0x08057a64 in GtkChangeLabel (pic_no=1) at gtk2_control.c:370
#8  0x080577f5 in XVC_ChangeGUILabel (pic_no=1) at gtk2_control.c:260
#9  0x08060e51 in TCbCaptureSHM (xtp=0x82c1bf8, id=0x0) at capture.c:709
#10 0x08058093 in start_recording_nongui_stuff (job=0x82c1bf8) at gtk2_control.c:558 #11 0x080580d4 in on_record_toggled (togglebutton=0x82ef6a0, user_data=0x0) at gtk2_control.c:568








[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]