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 » IsFinished() for CoWork
IsFinished() for CoWork [message #14579] Mon, 03 March 2008 23:58 Go to next message
kodos is currently offline  kodos
Messages: 111
Registered: March 2008
Experienced Member
Hi,

I think that a function IsFinished() would be realy usefull in the CoWork class.

CoWork.h
...
	bool IsFinished();
...
	bool IsFinished()               { return true; }
	//In the singlethreaded version


CoWork.cpp
bool CoWork::IsFinished() {
	Pool &p = pool();
	p.lock.Enter();
	bool retVal = todo == 0;
	p.lock.Leave();
	return retVal;
}
Re: IsFinished() for CoWork [message #14611 is a reply to message #14579] Tue, 04 March 2008 15:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I do not really see the point. Usually, you use CoWork with loop in some block. CoWork destructor waits for finishing of all the work. Where/when should I check for being finished?

Mirek
Re: IsFinished() for CoWork [message #14619 is a reply to message #14579] Tue, 04 March 2008 18:37 Go to previous messageGo to next message
kodos is currently offline  kodos
Messages: 111
Registered: March 2008
Experienced Member
Hi,

I have a CoWork instance where I add some callbacks which have some calculations to do and after they are finished I want to display the result on my GUI. But I don't want to call coWork.Finish() and thus hang my GUI. So I've set up a Timer that calls every 100ms a function which checks if the coWork is finished with executing all my callbacks and if they are finished I can update my GUI.
If there is another simpler way to do this I would like the hear it Smile .
Re: IsFinished() for CoWork [message #14625 is a reply to message #14619] Tue, 04 March 2008 21:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Run the computation in separate thread, then post callback "finished"? Smile

(BTW, note that only main thread is allowed to do GUI...)

Mirek
Re: IsFinished() for CoWork [message #14628 is a reply to message #14625] Tue, 04 March 2008 23:48 Go to previous messageGo to next message
kodos is currently offline  kodos
Messages: 111
Registered: March 2008
Experienced Member
luzr wrote on Tue, 04 March 2008 21:37

Run the computation in separate thread, then post callback "finished"? Smile

(BTW, note that only main thread is allowed to do GUI...)
Mirek


But that's the point: How should I update the GUI in my callback if I'm not allowed to?

I could poll an a variable if it is finished but then my solution with IsFinished would be easier IMHO.
Re: IsFinished() for CoWork [message #14634 is a reply to message #14628] Wed, 05 March 2008 09:54 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
kodos wrote on Wed, 05 March 2008 00:48


But that's the point: How should I update the GUI in my callback if I'm not allowed to?

I could poll an a variable if it is finished but then my solution with IsFinished would be easier IMHO.


The point is that only you main thread can update the GUI. If you're callback belongs to the main thread, then there is no problem with it. Create the callback member function in you main window class for example, and everything will work fine.

Did you look over reference/GuiMT example? It creates a callback at the end of the thread with Divisors::ShowResult, which then does the updating.
Re: IsFinished() for CoWork [message #14647 is a reply to message #14634] Wed, 05 March 2008 19:44 Go to previous message
kodos is currently offline  kodos
Messages: 111
Registered: March 2008
Experienced Member
cbpporter wrote on Wed, 05 March 2008 09:54


The point is that only you main thread can update the GUI. If you're callback belongs to the main thread, then there is no problem with it. Create the callback member function in you main window class for example, and everything will work fine.

Did you look over reference/GuiMT example? It creates a callback at the end of the thread with Divisors::ShowResult, which then does the updating.


Ah, OK thank you, I didn't know that this is possible. I thought if you call a callback in an other thread, it will be called in the context of that thread.
Previous Topic: CPU_Cores() error
Next Topic: CoWork buggy!?
Goto Forum:
  


Current Time: Thu Apr 18 18:19:08 CEST 2024

Total time taken to generate the page: 0.01429 seconds