Re: gdk_threads_leave in gtk callback ?



Vladimir wrote:

There are two uses of GTK+ in non-main threads:
1. error reporting via message boxes and 
2. adding text (which comes from network) to GUI windows.

Btw, if you don't use modal message box dialogs then there is absolutely
no need to use multiple threads (aka one to receive, the other one to
display) at all. One single thread can perfectly handle this chain of
actions:
- wait for data from network and receive into buffer if there's any
- add received buffer data to a text display
- open a (non-modal) message box to report errors if there are any

The non-modality of the dialog assures that reception anmd display of
incoming data would continue at the same time. For instance, if you use
select() or poll() to wait for network data in the other thread, better
have a look at this:

http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#GSource
http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html#g-source-add-poll

This way you can do completely without multiple threads for all sorts of
asynchronous I/O regarding network traffic and GTK+ visualization. Doing
without threads is always easier to debug and also prevents creating
some hard to find bugs while writing the code.

Unless your application includes massive computations of data (in which
multiple threads can be beneficial on multi-core systems, indeed),
single-threaded apps may also save a tiny amount of CPU time and code
size, since there is no need for thread switches and mutexes and all
that stuff. So, if there are no other reasons for multiple threads than
being able to receive and display "simultaneously", you should perhaps
consider to abandon the multi-threadity of your application at all?



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