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 example
Re: Simple thread example [message #29577 is a reply to message #29574] Mon, 01 November 2010 12:59 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1791
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Neilson,

First a hint: you can search in package selection dialog and in help inside theide. It is usually faster (and as it seems even more reliable Smile ) than windows file search Wink

Probably simplest possible example suiting your needs:
#include <Core/Core.h>
using namespace Upp;

void ThreadFn(){
	while(!Thread::IsShutdownThreads()){
		Cout()<<"doing something here\n";
		Sleep(1000);
	}
}

CONSOLE_APP_MAIN{
	Thread::Start(callback(ThreadFn));
	Sleep(4000);
	Thread::ShutdownThreads();
}
Note that you have to set MT flag to compile it (otherwise Thread is not defined).

If you need finer control of the thread, you can also use little bit different syntax:
	Thread t;
	t.Run(callback(ThreadFn));
The variable t can than be used for example to Wait() for the thread to end or set its priority(win32 only).

Best regards,
Honza

[Updated on: Mon, 01 November 2010 13:02]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Upp (Help) documentation
Next Topic: Few questions
Goto Forum:
  


Current Time: Tue Jul 08 07:55:46 CEST 2025

Total time taken to generate the page: 0.03582 seconds