Re: gtk_label_set_text () BUG !?!?!?!?!??!?!?!??!!? ( N00b)



On Aug 9, 2006, at 8:04 PM, hm wrote:
I`m workin` on a chessgame project. I`m willing to use GLib threads to make ticking clock visible in my GUI. Thread function modifies ( by gtk_label_set_text () ) text in label, which`s pointer is given as a parameter to Thread. The problem is, that when the thread function is modyfying text, application slows down, and after first modification of label it is impossible to do anything. No reaction. If gtk_label_set_text () is removed, everything is all right. Is it a bug ? or what ? any clue ?

It sounds like you're violating some cardinal principles of multithreaded GUI programming....

Rule #1 on multithreading GUI's: don't do it if you don't need to. Your timer can be updated using GTK's idle or timeout callbacks.

Rule #2: Only ever call the GUI system from one thread (your main thread). This rule can be different on some platforms, but in general, and particularly with GTK, this is the rule. In GTK you can call from other threads (I think) by wrapping calls in g_threads_enter/g_threads_leave pairs, but IMHO it'd be better to use those only to protect setting an idle callback so that your worker thread actually schedules the display update to happen in the main thread. I'm evaluating adding a similar mechanism in my program so that some complex computations and network polling (using libraries not integrated w/ glib) can be run in separate threads.

Make sure you're following those rules, and then see what happens. I'm guessing the problem is caused by calling GTK from multiple threads.

- Michael



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