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 » Wait for other Threads
Re: Wait for other Threads [message #46587 is a reply to message #46579] Sat, 04 June 2016 02:30 Go to previous messageGo to previous message
funky1221 is currently offline  funky1221
Messages: 3
Registered: May 2016
Junior Member
I used ProcessEvents() but threads still inside the loop.
just refresh GUI.

If I use PromptOK inside the loop, threads seems to be finished, why ?

But I changed "void testU::Searchfile" to "void Searchfile" and used PostCallback referenced from GuiMT,
it worked.



koldo wrote on Fri, 03 June 2016 08:50
Hello funky

I am not an expert in multi threading and in my projects I use another focus. However I see two things in your code:

- I would replace while(Thread::GetCount()); with:
while(Thread::GetCount()) {
	ProcessEvents();
	Sleep(0);
}

I think that with while(Thread::GetCount()); you are locking main thread with an infinite loop, and Guilocks in threads will wait forever.
Calling ProcessEvents(); inside the loop you let the GUI to be refreshed by the threads you have launched.

- intfile
This is a variable handled globally by different threads without any control, so results will be undefined...
A safer way could be to declare intfile as Atomic and increase it with AtomicInc:
Atomic intfile;
...
AtomicInc(intfile);
intfile will behave as an int, but multiple threads will access it safely.

 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: how to use the TcpSocket::Get?
Next Topic: skylark meet strange problem
Goto Forum:
  


Current Time: Fri Jun 27 17:08:37 CEST 2025

Total time taken to generate the page: 0.04309 seconds