Re: Problem with threads in my GTK+ application...



Dutta, Seemanta schrieb:
The way I decided to remedy this problem was with the below steps:

1. Call g_thread_init() in the main function before gtk_init() is
called.
2. In the callback for 'clicked' signal for the'Burn' button, I use
g_thread_create() to create a new thread which will handle the burning
of the micro processor.
3. I immediately return from  the callback and control goes back to the
main loop.

MY PROBLEM: With the above approach, my application works for the first
time. It just works perfectly. All the logs in the textviewer come up in
sync with the actual process. 

This looks as the usual problem: Your description sounds like you are
updating the textview from *within* the worker thread.
Although it's possible to update the GUI from more than one thread
this is not recommend, as it is tricky to do the locks the right way.
I suggest you should search this mailing list for threading, this
is discussed here nearly once a week.

Only when I press BURN for the second time, the textviwer does not show
any logs, although I can see log statements in my console and it also
performs its work of programming the microprocessor.

The locking seem to be wrong...

I'll try to remove all Gtk calls from worker thread and only update
the GUI from main Gtk thread. The data for the log textviewer
can be sent with a thread save queue (with locking) or simple over
a pipe.

Cheers, Andy



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