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++ Callbacks and Timers » Kill callbacks when parent is destructed
Kill callbacks when parent is destructed [message #43572] Tue, 02 September 2014 18:04 Go to next message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
Hello,

I have a question about callbacks. I'm using a TopWindow that creates asynchronous callbacks. When the TopWindow is closed, it may be possible that one of the callbacks are still being executed. I changed the declaration to PTEBACK2 instead of THISBACK2, which seemed to help for most cases. However, I still experience problems. Now I know that you cannot just terminate an execution path. I could build in the necessary synchronization. However, when I saw the PTEBACK alternative, I was thinking: Does U++ provide a method to prevent crashing when execution PTEBACK's when its parent TopWindow is closed a.k.a. destroyed? Is there a simpler solution I can build in to suppress the situation?

Thanks,

crydev
Re: Kill callbacks when parent is destructed [message #43573 is a reply to message #43572] Tue, 02 September 2014 18:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
crydev wrote on Tue, 02 September 2014 18:04
Hello,

I have a question about callbacks. I'm using a TopWindow that creates asynchronous callbacks. When the TopWindow is closed, it may be possible that one of the callbacks are still being executed. I changed the declaration to PTEBACK2 instead of THISBACK2, which seemed to help for most cases. However, I still experience problems. Now I know that you cannot just terminate an execution path. I could build in the necessary synchronization. However, when I saw the PTEBACK alternative, I was thinking: Does U++ provide a method to prevent crashing when execution PTEBACK's when its parent TopWindow is closed a.k.a. destroyed? Is there a simpler solution I can build in to suppress the situation?

Thanks,

crydev


Not sure I understand all detail properly, but when it is possible that parent TopWindow is destroyed _while_ _executing_ Callback, then you have violated multithreading rules (whole GUI is shared resource, only one thread is allowed to run GUI and some operations like opening/closing windows are allowed only for the main thread).
Re: Kill callbacks when parent is destructed [message #43574 is a reply to message #43573] Thu, 04 September 2014 09:25 Go to previous messageGo to next message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
mirek wrote on Tue, 02 September 2014 18:44
crydev wrote on Tue, 02 September 2014 18:04
Hello,

I have a question about callbacks. I'm using a TopWindow that creates asynchronous callbacks. When the TopWindow is closed, it may be possible that one of the callbacks are still being executed. I changed the declaration to PTEBACK2 instead of THISBACK2, which seemed to help for most cases. However, I still experience problems. Now I know that you cannot just terminate an execution path. I could build in the necessary synchronization. However, when I saw the PTEBACK alternative, I was thinking: Does U++ provide a method to prevent crashing when execution PTEBACK's when its parent TopWindow is closed a.k.a. destroyed? Is there a simpler solution I can build in to suppress the situation?

Thanks,

crydev


Not sure I understand all detail properly, but when it is possible that parent TopWindow is destroyed _while_ _executing_ Callback, then you have violated multithreading rules (whole GUI is shared resource, only one thread is allowed to run GUI and some operations like opening/closing windows are allowed only for the main thread).



Thanks for your reply Mirek,

The callbacks I am executing run on seperate threads, using Thread().Run(...). This way, I can close the window without affecting the running threads. I am not operating on the user interface from other threads. I assume that scheduled PostCallback's are automatically removed when the TopWindow is closed, so one of my threads should be causing the problem.

Thanks

crydev
Re: Kill callbacks when parent is destructed [message #43575 is a reply to message #43574] Thu, 04 September 2014 12:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
crydev wrote on Thu, 04 September 2014 09:25

I am not operating on the user interface from other threads. I assume that scheduled PostCallback's are automatically removed when the TopWindow is closed, so one of my threads should be causing the problem.


Only Callbacks with id's (and id must >= and < (int)sizeof(Ctrl)) are alternatively removed. Aternatively, TimeCallback helper class callbacks are removed by TimeCallback destructor.

PTE callbacks are not removed, but they are 'emptied' when pointee destructs.
Re: Kill callbacks when parent is destructed [message #43581 is a reply to message #43575] Sat, 06 September 2014 19:32 Go to previous message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
Thanks Mirek,

Interesting to know about PTEBACK's whereabouts, thanks. I'm going to try to implement basic synchronization to prevent the PostCallbacks from running. I think the problem is inside those.

Regards,
evo
Previous Topic: Feature request
Next Topic: Event.execute
Goto Forum:
  


Current Time: Thu Mar 28 20:07:14 CET 2024

Total time taken to generate the page: 0.00830 seconds