Multiple threads: one interface



I've created this GTK+2.0 app that has threads in the following setup:

1. thread Main launches gtk_main();
2. thread A collects network data and passes it to update_treeview, a
function that directly manipulates the gui.
3. thread B runs within the gui and performs cleanup on it. Every 1
second, it checks for outdated entries in the treeview and udpates their
display.

Some background:
update_treeview and thread B share a semaphore that prevents them from
both accessing the gui at the same time (a mutex of sorts). While one is
manipulating the gui, the other is not allowed to touch the gui. Also,
g_thread_supported() returns false, and g_thread_init() seg faults.
Occasionally, I get an "Xlib: unexpected async reply" error.

The question:
So, my general question is this: How do I thread-safe this program? I've
tried putting gtk_main in a thread separate from main and running thread
A there instead, but that produces the same results. Could my semaphore
be insufficient to prevent a race condition? Should I add some kind of
mutex to prevent a context-switch?

Thanks for the help,
Dave






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