I have multiple threads that calculate thumbnails of images. The
program creates a Table to contain the images.
Once an image is available (which is calculated by worker threads) , a
signal containing the image is sent from that thread
so that it can be put inside the table. Inside the slot Ithat handles
a new thumbnail available I attach the image to the table and then
call the dispatcher(),
which calls show_all().
Is this correct?
The (simplified) code is something like this:
class GUI : public Gtk::Window
{
private:
Glib::Dispatcher d_;
Gtk::Table * table_;
Gtk::Button buttonprocessimages_;
Gtk::Label l_;
ThreadPool & pool_;
void onImageAvailable(...)
{
table_->attach(*img, row, col,...);
d_();
}
void redraw()
{
show_all();
}
void processImages()
{
table_ = Gtk::Manage(new Gtk::Table(........
pool_.set_max_threads(n);
send_work_to_process...
label_.set_text("");
buttonprocessimages_.set_sensitive(false);
}
public:
GUI(Glib::ThreadPool & pool) : pool_(pool)
{
buttonprocessimages_.connect(sigc::mem_fun(*this, &GUI::processImages));
signal_image_available.connect(sigc::mem_fun(*this,
&GUI::onImageAvailable));
d_.connect(sigc::mem_fun(*this, &GUI::redraw));
}
};