Home » Community » Newbie corner » Simple Thread (simple thread example.)
Re: Simple Thread [message #55032 is a reply to message #55023] |
Mon, 05 October 2020 18:12   |
 |
Klugier
Messages: 1106 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
It seems that you have missed "typedef Processus CLASSNAME;" (C++03) "using CLASSNAME =Processus" (c++11) declaration in your class. However, in c++11 world you don't need this just replace with lambda:
void Processus::Start( String parametres )
{
Thread thr;
thr.Run([=] { Boucle(parametres); }); // <- In previous implementation you delete thread model immediately...
while(thr.GetCount()); // <- Not very nice synchronization mechanism :)
}
void Processus::Boucle( String parametres )
{
for (int i = 0; i < 10; ++i)
{
Cout() << i << ","; // <- Cout() better in U++ world!
}
}
My working test code below:
#include <Core/Core.h>
using namespace Upp;
class Processus {
public:
void Start( String parametres )
{
Thread thr;
thr.Run([=] { Boucle(parametres); }); // <- In previous implementation you delete thread model immediately...
while(thr.GetCount()); // <- Not very nice synchronization mechanism :)
}
void Boucle( String parametres )
{
for (int i = 0; i < 10; ++i)
{
Cout() << i << ",";
}
}
};
CONSOLE_APP_MAIN
{
Processus().Start("asda");
}
Klugier
U++ - one framework to rule them all.
[Updated on: Mon, 05 October 2020 18:12] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Aug 24 08:14:14 CEST 2025
Total time taken to generate the page: 0.03767 seconds
|