Multi threaded program using a modal dialog box

Hello,
I am writing a piece of code using gtkmm and ran into this problem. This is how i am getting the problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class someobj
{

Gtk::Window* pWindow;
// Thread 2
void run()
{
   while(1)
   {
       // Do blah blah blah
       // Open dialog Box with parent obj as Gtk::Window window;       
       Gtk::MessageDialog dialog(*pWindow, "blah");
       dialog.run();   // SIGABRT happens sometimes but sometimes it dosent
       // sleep or exit when condition satisfies
   }
}
}

// Thread 1
main()
{
  // create a thread for someobj.run()
  Gtk::Window window;
  // start window 
  return app->run(window);
  //Join thread for some object.run()
}



I think it is not dependent on gtkmm because thread 2 is blocked where as the parent thread is running which is causing the problem, but am confused on how to resolve this... any suggestion will be helpful
I haven't used gtkmm, but generally: Do not use Gui elements in different threads
so the problem is in design...
so how to people usually go about avoiding such things??
Gui usually depends an sending messages.

A message is send for instance when a user selects a menu. A message dialog that runs independent from the underlying Gui usually makes no sense.

See the documentation on how this works. Like this:

https://developer.gnome.org/gtkmm-tutorial/stable/chapter-signals.html
yes i agree a dialog running independent of GUI doesnt make sense,

but my problem is a little different...

suppose say the main thread is for the gui and a child thread is monitoring some other resource, say a website, when that website is available the child thread needs to display a yes/no message box to ask the user something...
so how would this normally work??
The child would send a message to the parent, and when the parent gets the response from the user it would send that in a message back to the child.
could you give an example?
Edit:
thanks for the suggestions, i think i can make it with 2 bools and a timed signal :)
Last edited on
Topic archived. No new replies allowed.