Re: Work woth GUI from a thread that was made by pthread_create function



On 2002.02.02 13:32 admin kiesoft com wrote:
Hi!

I'm writing GNOME/GTK+ application for Linux that has a few work
thread. Each thread made by "pthread_create" function). When I try to
access GUI from child thread (thread that was made by main process) my
app is locked or dumped. What I have to do to be able wprk with GUI
from a thread that was made by "pthread_create"?

You need to link your app with gthread library, and in the code, at the very beginning, call

    g_thread_init(NULL);

You need to lock gdk mutex before entering the main loop.

    gdk_threads_enter();
    gtk_main();
    gdk_threads_leave();

You may look up, for example, balsa sources (not that it is a best example, but it is a sufficiently complex one).

Generally, threading GDK (or I think most GUIs) with threads is a non-trivial thing (threads are non-trivial, GUI are non-trivial, and the system mixing these together becomes quite complex). If you can steer clear of it, do.

-pawel
--
Pawel Salek (pawsa theochem kth se) http://www.theochem.kth.se/~pawsa/
Theoretical Chemistry Division, KTH



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