I have working code without a GUI which manages some threads. Now I want to integrate it with a GUI created in GTK. It builds the GUI with test_glade
which makes use of gtk::main
:
fn main() {
//..
test_glade();
//..
// Question about this
while estado < 4 {
if *count.lock().unwrap() == arc_pref.cantidad {
estado = 3;
}else if estado == 2{
estado = 1;
}else if estado == 1{
estado = 2;
}else if *count.lock().unwrap() == 0 && estado == 3{
estado = 1;
}
//..
estados(count.clone(), arc_pref.clone(), estado).join();
}
}
fn test_glade(){
gtk::init();
//..
window.show_all();
gtk::main();//main loop gtk
}
//..
After looking, I see that this is the main loop, so my code does not run.
//..
test_glade();
//..
// Question about this
while estado < 4 {
//..
estados(count.clone(), arc_pref.clone(), estado).join();
}
How can I integrate my code which uses some threads into the GTK main loop?
For now I have created a new thread, and I have put the code inside the thread, and it seems to work:
fn test_glade(){
gtk::init();
//..
thread::spawn(move|| {
//code Question
});
//..
window.show_all();
gtk::main();//main loop gtk
}
//..