Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
Klugier is currently offline  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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to load your GridCtrl in background thread
Next Topic: Translation files
Goto Forum:
  


Current Time: Sun Aug 24 13:13:25 CEST 2025

Total time taken to generate the page: 0.04459 seconds