Why Glib::IOChannel in a thread blocks GUI mainloop ?



In my Gtkmm programm that is written in C++ I have a windows that contains a button and a progress bar,

If the user presses the button the program will create a thread to do its job and by the help of

Glib::Dispatcher updates the progress bar in main GUI window.

Inside the thread it executes a system command by calling Glib::spawn_async_with_pipes()

To access the output of the command which is executed by Glib::spawn_async_with_pipes (),

I used Glib::IOChannel (I need a portable code to M$ Windows), but after googling I realized

that it isn't thread-safe to connect a slot to Glib::signal_io() that belongs to mainloop

of main GUI inside a thread.

So I created a seperate Glib::MainLoop inside my thread, get its Glib::MainContext and connected

my slot to its signal_io ().

But after using Glib::IOChannel inside my thread the gui can not be updated, it seems that

something blocks the GTK+ mainloop.

So my question is how one should safely use Glib::IOChannel inside a thread that runs

it's own Glib::MainLoop?

I really appreciate it if you guys don't advise me about a change in internal design of the program and don't try to convince

me not to use threads or a MainLoop inside it, the whole project is for educational proposes and I just want to learn

more about multi-threading in GTKmm.

Thank you so much in advance for considering my question and helping me out.

Ehsan Aali.







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