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 » Problem breaking loop (with close button) in main thread
Re: Problem breaking loop (with close button) in main thread [message #59044 is a reply to message #59043] Thu, 20 October 2022 01:04 Go to previous messageGo to previous message
Lance is currently offline  Lance
Messages: 656
Registered: March 2007
Contributor
Hi Awksed

I am sorry to hear that you have to satisfy with a compromise.

I manage to create the following test. It runs as expected on Linux, but would not work on Windows.

Regards,
Lance

----------------
Correction: No, it's not a problem with ProcessEvents(). After I change the thread lambda to not log on GUI but to debug output file, it runs like a charm. It's interesting. I probably should not modify GUI from within other than the GUI thread. Seems Linux+GTK are more tolerant to this kind of error.
	void Start(){
		static int cnt;
		if( cnt!= 0 )
			return;
		++ cnt;
		stop_requested = false;
		log.Clear();
		badguy.Run([this]{
			LOG("Badguy running...\n"); // CHANGE THIS
			Mutex::Lock _(mut);
			LOG("Badguy now owns the Mutex.\n");  // CHANGE THIS
			while(!stop_requested && !IsShutdownThreads() ){
				Sleep(50);
			}
			LOG("Stop requested, Badguy exiting and releasing the Mutex...\n"); // AND THIS
		});

		// wait for badguy to acquire the mutex
		while(mut.TryEnter()){
			mut.Leave();
			ProcessEvents();
			Sleep(100);
		}

		log.Append("Trying to acquire the mutex...\n");
		GuiAcquireMutex();
		--cnt;
	}

[Updated on: Thu, 20 October 2022 13:09]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Dealing with background tasks elegantly in a userinterface
Next Topic: error / memory leak in HttpServer example
Goto Forum:
  


Current Time: Tue Aug 26 10:47:33 CEST 2025

Total time taken to generate the page: 0.05257 seconds