I'm working on a C++ FLTK application. This is a multi-thread application that creates & shows a modal window in a thread using below code:
Fl_Double_Window* dlg = new Fl_Double_Window(0, 0, 200, 100);
...
dlg->set_modal();
Fl::visual(FL_DOUBLE|FL_INDEX);
dlg->show();
then in same thread I create a new thread & pass pointer to Fl_Double_Window
object to it as thread parameter:
CreateThread(
NULL, // default security attributes
0, // use default stack size
&beginProgress, // thread function name
(LPVOID) dlg, // argument to thread function
0, // use default creation flags
NULL);
& in my thread function I do some operations & then I need to hide the showing modal window:
DWORD WINAPI beginProgress(LPVOID args)
{
//do some operations
((Fl_Double_Window*)args)->hide();
return 0;
}
the problem is here that my code executes successfully with no error, but after executing hide
method of dlg
object pointer, window does NOT hides & seem calling hide
or even deleting window object using delete dlg
has no effect.
I guess this problem is related to multi-threading behavior, but I can't guess what cause the problem & how should I solve it.