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 » Question about Threads
icon5.gif  Question about Threads [message #25917] Fri, 19 March 2010 18:07 Go to next message
Reini is currently offline  Reini
Messages: 28
Registered: April 2009
Location: Berlin
Promising Member
Hello upp Team,

I am experimenting a bit with Thread programming in upp and encountered an error.
The compiler did not recognize the thread class name.

The example GUIMT runs without errors from which I took most of the code, but my application does not recognize the thread class.


class MyClass : public WithMyClassLayout<TopWindow> 
{
public:
	typedef MyClass CLASSNAME;
	MyClass();
	void StartPlay();
	
	//thread handling
	volatile Atomic terminated;
	volatile Atomic threads;	
};

typedef struct {
	MyClass *gui;
} PlayInfo;

//thread callback
void WorkerThread(PlayInfo f)
{
    while (true)
    {
		if(f.gui->terminated)
			break;
		//playfile
		
    }
	AtomicDec(f.gui->threads);
}

//Callback of button
void MyClass::StartPlay()
{
	PlayInfo f;
	f.gui = this;
	AtomicInc(threads);
	Thread().Run(callback1(WorkerThread, f));//error in this line
}


Output:
error C2228: Left of ".Run" has to be a class/struct/union
Typ is ''unknown-type''
error C3861: "Thread": Identifier was not found.


Thank you for comments and help Smile

Re: Question about Threads [message #25920 is a reply to message #25917] Fri, 19 March 2010 21:25 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Reini wrote on Fri, 19 March 2010 18:07

Hello upp Team,

I am experimenting a bit with Thread programming in upp and encountered an error.
The compiler did not recognize the thread class name.

The example GUIMT runs without errors from which I took most of the code, but my application does not recognize the thread class.


class MyClass : public WithMyClassLayout<TopWindow> 
{
public:
	typedef MyClass CLASSNAME;
	MyClass();
	void StartPlay();
	
	//thread handling
	volatile Atomic terminated;
	volatile Atomic threads;	
};

typedef struct {
	MyClass *gui;
} PlayInfo;

//thread callback
void WorkerThread(PlayInfo f)
{
    while (true)
    {
		if(f.gui->terminated)
			break;
		//playfile
		
    }
	AtomicDec(f.gui->threads);
}

//Callback of button
void MyClass::StartPlay()
{
	PlayInfo f;
	f.gui = this;
	AtomicInc(threads);
	Thread().Run(callback1(WorkerThread, f));//error in this line
}


Output:
error C2228: Left of ".Run" has to be a class/struct/union
Typ is ''unknown-type''
error C3861: "Thread": Identifier was not found.


Thank you for comments and help Smile



Hello Reini

I can answer you with a 99,999% of possibilities Smile that the problem comes from you have not included in "Project/Main package configuration" the option MT (multi thread).


Best regards
Iñaki
icon14.gif  Re: Question about Threads [message #25921 is a reply to message #25917] Fri, 19 March 2010 22:38 Go to previous messageGo to next message
Reini is currently offline  Reini
Messages: 28
Registered: April 2009
Location: Berlin
Promising Member
Hello Koldo

Thanks for your help ! It worked Razz

But anyway it was way complicated to activate the MT Flag in an already existing project since I did not found a possibility to acitvate the MT switch if the project already exists.

So I had to do that manually in the upp Project File and then only it worked.

Nice weekend so far
Re: Question about Threads [message #25930 is a reply to message #25921] Sat, 20 March 2010 20:44 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Why was it hard? "Project/Main package configuration" as said above, press Insert or right click and select menu to insert a new configuration, an type MT there. Or if you have already a configuration, you can add it to that.

Recompile is needed.
Re: Question about Threads [message #25932 is a reply to message #25930] Sat, 20 March 2010 21:37 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
cbpporter wrote on Sat, 20 March 2010 20:44

Why was it hard? "Project/Main package configuration" as said above, press Insert or right click and select menu to insert a new configuration, an type MT there. Or if you have already a configuration, you can add it to that.

Recompile is needed.

Yes, it is really very easy.

Just clicking there Twisted Evil

index.php?t=getfile&id=2411&private=0
  • Attachment: Dib.PNG
    (Size: 21.29KB, Downloaded 447 times)


Best regards
Iñaki
Previous Topic: new
Next Topic: Problem installing Upp under Ubuntu
Goto Forum:
  


Current Time: Thu Mar 28 14:53:24 CET 2024

Total time taken to generate the page: 0.00915 seconds