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 » U++ Library support » U++ MT-multithreading and servers » How do I create a loop for a window to react to volatile changes to a global variable?
Re: How do I create a loop for a window to react to volatile changes to a global variable? [message #51336 is a reply to message #51335] Mon, 11 March 2019 13:29 Go to previous messageGo to previous message
slashupp is currently offline  slashupp
Messages: 231
Registered: July 2009
Experienced Member
Hi Oblivion

What I do is more like this:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class ThreadTest;
void RunThread(ThreadTest *pTT);

class ThreadTest : public TopWindow
{
	Button    start;
	ArrayCtrl array;
public:
	ThreadTest()
	{
		SetRect(0, 0, 800, 600);
		CenterScreen();
		array.AddColumn("Number");
		Add(array.HSizePos().VSizePos(0, 30));
		Add(start.SetLabel("Start Thread").RightPos(2, 120).BottomPos(2, 26));
		
		start << [=] {  RunThread(this); };
	}
	void SetArray(int n)
	{
		GuiLock __;
		array.Add(n);
		if(n == 10) { // Resize window from within thread...
			SetRect(0, 0, 640, 480);
		}
	}
};

void RunThread(ThreadTest *pTT)
{
	Thread t;
	ThreadTest *ptt=pTT;
	t.Run([=]
	{
		for(int i = 1; i < 10; i++)
		{
	        // GuiLock __;
			ptt->SetArray(i);
		}
	});
	t.Detach();
}


GUI_APP_MAIN
{
	ThreadTest().Run();
}


Where the thread-func is global. This still works, and the only real difference
between my app and this is that I use std::thread ... maybe I shouldn't
I'll change my code to use Upp::Thread
(and if you don't hear from me again, it worked)

thx
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: AsyncWork, IsFinished() may not be working properly
Next Topic: Encoding URL for HttpRequest
Goto Forum:
  


Current Time: Fri May 03 18:56:34 CEST 2024

Total time taken to generate the page: 0.02422 seconds