Home » U++ Library support » U++ MT-multithreading and servers » MT app hangs
Re: MT app hangs [message #24022 is a reply to message #24014] |
Thu, 17 December 2009 18:20 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
mdelfede wrote on Thu, 17 December 2009 07:51 | Hi, Mirek, thank for your answer
Anyways, I don't see a simple solution to my problem, indeed.
As far as I can understand, I can't use Wait() from inside the button callback, or anyways can't wait for the thread to stop from inside a gui event handler, as the thread could try a GuiLock between the Wait() call and its termination.
|
Ha! That is true.
Well, that is the hard part of MT...
I guess the really bad issue here is the Wait call. I thing things would be much simplified if you avoided Wait and posted callback at the end of thread.
Quote: |
Why does Gui need to be locked inside event handlers ?
|
Because it does a lot of things to GUI status. E.g. setting focuses, changing widget status etc...
In theory, the locking could be much fine-grained (like locking individual widgets before accessing them). But doubt it would be any easier....
Quote: |
Or there's a nicer solution ?
|
void TestThread::thrCb(void)
{
{
GuiLock __;
status.Set("Running, " + FormatInt(thr.GetCount()) + " threads");
}
for(;;)
{
{
GuiLock __;
if(progress < 100)
progress++;
else
progress = 0;
if(stop)
break;
}
Sleep(1000);
}
{
GuiLock __;
status.Set("Idle....");
}
PostCallback(THISBACK(Stop));
}
void TestThread::Stop()
{
button.SetLabel("START");
}
void TestThread::buttonCb(void)
{
if(stop)
{
stop = false;
button.SetLabel("STOP");
thr.Run(THISBACK(thrCb));
}
else
stop = true;
}
|
|
|
Goto Forum:
Current Time: Mon May 20 02:06:10 CEST 2024
Total time taken to generate the page: 0.00866 seconds
|