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   |
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
|
|
|
 |
|
Problem breaking loop (with close button) in main thread
By: awksed on Tue, 18 October 2022 17:19
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Tue, 18 October 2022 19:15
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Tue, 18 October 2022 20:09
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: awksed on Wed, 19 October 2022 01:11
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Wed, 19 October 2022 02:21
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Wed, 19 October 2022 02:42
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: awksed on Wed, 19 October 2022 20:56
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Thu, 20 October 2022 01:04
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Oblivion on Thu, 20 October 2022 20:10
|
 |
|
Re: Problem breaking loop (with close button) in main thread
By: Lance on Thu, 20 October 2022 21:49
|
Goto Forum:
Current Time: Tue Aug 26 10:47:33 CEST 2025
Total time taken to generate the page: 0.05257 seconds
|