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 » MT again
Re: MT again (SOLVED!) [message #24028 is a reply to message #24026] Fri, 18 December 2009 12:51 Go to previous messageGo to previous message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
// calculation thread function
void CalcPage::DoCalculation(void)
{
	bool mod;

	INTERLOCKED_(mutex)  {
		inThread = true;
	}
	do
	{
		INTERLOCKED_(mutex)  {
			modified = false;
		}

		// gets the status bar
		StatusBar &sb = ((Lamell *)(GetMainWindow()))->GetStatusBar();
		{
			// signals calculation in progress
			GuiLock __;
			sb.Set("Calcolo in corso");
		}
		calcAborted = !Calculate();
		{
			// signals end of calculation
			GuiLock __;
			if(calcAborted)
				sb.Set("Errore");
			else
				sb.Set("Pronto");
		}
		INTERLOCKED_(mutex) {
			mod = modified;
		}
	}
	while(mod);
	INTERLOCKED_(mutex) {
		inThread = false;
	}
}

// modify handler -- triggers page calculation
// on keypress on every (editable) ctrl on page
void CalcPage::ModifyCb(void)
{
	bool inTh;
	INTERLOCKED_(mutex) {
		inTh = inThread;
	}
	if(!inTh)
	{
		calcThread.Run(THISBACK(DoCalculation));
		return;
	}
	INTERLOCKED_(mutex) {
		modified = true;
	}
}


Well, thanks Mirek ! Smile
I'll post the correct code here for reference.

The problem was that IsOpen() just checks that the thread was STARTED right, not if the thread is still active.
To check for it, I added a new variable set inside the thread (inThread).

This snippet allows to have a long time backround calculation without stopping the gui and with results displayed as soon as available.
The thread routine can handle changes in data that happens during the calculation, re-entering itself when finished.

Ciao

Max
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: HttpQuery - not working?
Next Topic: CGI-BIN bug with Apache Server
Goto Forum:
  


Current Time: Sat May 11 13:15:30 CEST 2024

Total time taken to generate the page: 0.02822 seconds