Continues thread "synchronization"



Hi to all,

I'm using Gtkmm create a application containing user interface for
showing outputs from parallelized mathematical algorithms. It was
decided to contain the algorithms in the same process of the GUI, due to
this constraint it is needed to use threads the process.

I have comprehend that only one thread can manage the Gtk widgets and
I've done so. Meanwhile I'm having a problem were I can't find solution,
for which I ask your help.

I want to create a two states machine in the application:
 - Mathematical algorithms in idle mode.
 - Mathematical algorithms running.

I was thinking use the semaphore mechanism to idle the desired threads,
and then wake them all together.

-----
while (wait_cond)
{
    // calculate

    if (finish_thread ())
    {
       break;
    }
}
-----

I've found that we can use Glib::Cond to synchronize the threads,
unlocking all threads with Glib::Cond::broadcast method. But from where
I understand I cant use the Glib::Cond in my algorithm or else the GUI
thread must unlock each period.

I can use a variable to perform a checking before each time I call
Glib:Cond, but this method is much error prune.

Exist some mechanism in the Gtkmm API to use directly in this algorithm?

Best regards
Pedro


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