Home » Community » Newbie corner » MultiThreads and GLCtrl
MultiThreads and GLCtrl [message #28735] |
Tue, 14 September 2010 15:39 |
281264
Messages: 272 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
Hi,
I am interested in an example about how to use GLCtrl and multithread in U++. Is there anything (example) already done? If not, some hints would be great.
Thank you.
Cheers,
Javier
|
|
|
|
Re: MultiThreads and GLCtrl [message #28806 is a reply to message #28735] |
Fri, 17 September 2010 14:36 |
|
ratah
Messages: 107 Registered: July 2010
|
Experienced Member |
|
|
Hi,
Here is an example of multithread usage.
It's a copy of code posted here (or in the tutorial of upp, i do not remember). I give it a minor modification.
I have a bug: when you push the STOP button, it crash!
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class TestThread : public TopWindow
{
protected:
bool stop;
void buttonCb(void);
Thread thr1, thr2;
virtual void thrCb(void);
virtual void thrPerso(void);
ProgressIndicator progress;
int32 icounter;
Button button;
StatusBar status;
public:
typedef TestThread CLASSNAME;
TestThread();
};
void TestThread::thrCb(void)
{
for(;;)
{
GuiLock __;
if(progress < 100)
progress++;
else
progress = 0;
if(stop)
break;
Sleep(100);
}
}
void TestThread::thrPerso(void)
{
for(; ; )
{
{
GuiLock __;
icounter++;
status.Set(IntStr(icounter));
}
Sleep(100);
}
}
void TestThread::buttonCb(void)
{
if(stop)
{
stop = false;
button.SetLabel("STOP");
// I run here the first thread
thr1.Run(THISBACK(thrCb));
// I run here the second thread
thr2.Run(THISBACK(thrPerso));
}
else
{
stop = true;
thr1.Wait();
thr2.Wait();
button.SetLabel("START");
}
}
TestThread::TestThread()
{
SetRect(0, 0, 300, 150);
Add(button);
button.TopPos(90, 30).HCenterPos(100);
button.SetLabel("START");
Add(progress);
progress.TopPos(30, 40).HCenterPos(250);
progress.Set(0, 100);
icounter = 0;
AddFrame(status);
status.Set(" ");
stop = true;
button <<= THISBACK(buttonCb);
}
GUI_APP_MAIN
{
TestThread().Run();
}
Do not forget to change Configuration flags to Executable, GUI, Multithreaded!!
Hope you can fix the bug, good luck
RAtah
|
|
|
|
Re: MultiThreads and GLCtrl [message #28918 is a reply to message #28809] |
Sun, 26 September 2010 23:11 |
281264
Messages: 272 Registered: June 2010 Location: Spain
|
Experienced Member |
|
|
Hi Ratah
After some readings on the multithreading topic, I have modified the application you sent. I think now it works as you are expecting; test it and tell me.
Cheers,
Javier
|
|
|
Goto Forum:
Current Time: Fri Nov 01 00:26:42 CET 2024
Total time taken to generate the page: 0.01635 seconds
|