Re: Multi-threaded "gtk_main()"s
- From: Olivier Sessink <lists olivier pk wau nl>
- To: Nikolaj Kiær Thygesen <Nikolaj Thygesen ciber dk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Multi-threaded "gtk_main()"s
- Date: Mon, 16 Jan 2006 15:30:39 +0100
Nikolaj Kiær Thygesen wrote:
Hey list,
I'm currently writing a multi threaded gtk-app, and knowing that
calling gtk_main() simultaneously from different threads is a no-go,
it's more subtle: calling gtk functions simultaneous from different
threads is a no-go. gtk (and X) is not thread-safe. So as long as your
app does not call multiple gtk functions simultaneously it will work.
I was quite surprised to find that the following fragment seemed to
work when being accidentally called from a thread different from the
one which originally called gtk_main()!! I have initialized the
threading support properly before the initial call to gtk_main() in
the main thread, so I guess gdk_threads_enter() momentarily exits the
original gtk_main() - yes??? Is this really supposed to work, or did
I just get lucky???
gdk_threads_enter();
...
gtk_main();
gdk_threads_leave();
if I understand things correctly, gdk_threads_enter(); just makes sure
there is no other thread at that moment doing something inside a
not-thread-safe-function, and executes your block if that condition is
OK. So you can do anything inside the
gdk_threads_enter();/gdk_threads_leave(); block, except another call to
gdk_threads_enter();
regards,
Olivier
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]