#include âmywindow.hppâ #include <boost/lexical_cast.hpp> Glib:: StaticMutex mutex = GLIBMM_STATIC_MUTEX_INIT; MyWindow:: MyWindow (): m_end_thread (false), // of the Thread is to run m_vbox (false, 10), // Gtk:: VBox is not the elements homogeneous to put on // and 10 pixels place between the individual elements leave m_button (Glib:: locale_to_utf8 (âClick meâ)) // Button text set {ADDs (m_vbox); We connect the Gtk here for //:: VBox with the window m_vbox.set_border_width (10); // wing tip edge-rides the Gtk:: VBox on 10 pixels set m_vbox.pack_start (m_label); // connecting the Gtk:: Label with the Gtk:: VBox m_vbox.pack_start (m_pbar); // connecting the Gtk:: Progress bar with the Gtk:: VBox m_vbox.pack_start (m_button); // connecting the Gtk:: Button with the Gtk:: VBox m_pbar.set_pulse_step (0.05f); // step size for pulses () sets/to 0,0 - 1,0 // the Button the method, which it is to implement with clicked the signal, as // radio gate hand over m_button.signal_clicked () .connect (sigc:: mem_fun (*this, &MyWindow:: on_button_click)); // is handed m_dispatcher.connect the method those the dispatcher with the call to implement here is // as radio gate over (sigc:: mem_fun (m_pbar, &Gtk:: Progress bar:: pulses)); We start // here the 2. Thread (first is the Hauptthread!) for // us the progress bar - work will settle. // for this we hand to thread_worker method over as radio gate. // the âfalseâ says to the Thread which it not joinable to be is! // which also on the basis the pointer to the Thread shows and returned // are examined will. There we however do not need to ignore we // return value simply m_thread = Glib:: Thread:: create (sigc:: mem_fun (*this, &MyWindow:: more thread_worker), false); // now we let all elements of the window indicate. show_all (); } MyWindow:: ~MyWindow () {// a Anonymouer Scope within a function/a method has // purpose therein provided objects with abandoned to be destroyed // we to have here the Mutex:: LOCK object provides with production // the LOCK sets and during the destruction again unlockt {to Glib:: Mutex:: LOCK LOCK (mutex); if (m_end_thread) // if the Thread still runs m_end_thread = true; // say we to the Thread which it to terminate is} if (m_thread->joinable ()) m_thread->join (); } void MyWindow:: on_button_click () {static unsigned long count_clicked = 0; // we convert here the value of count_clicked and increment in immediately // and hand then the value over as Glib:: ustring to our label of far // thus we have then a Click more counter;) m_label.set_text (boost:: lexical_cast<Glib:: ustring> (count_clicked++)); } void MyWindow:: more thread_worker () {while (1) {Glib:: usleep (50000); // 50,000 microseconds wait more m_dispatcher (); // Threadsafer call pulses () - method // this is a more anonymous scope [to explanation see Destruktor Defintion] {Glib:: Mutex:: LOCK LOCK (mutex); if (m_end_thread) // having we to terminate? return; }/end of the anonymous scopes, that the effect has that mutex we unlocked becomes}}