Hi

I have a worker thread that shares its heap with the parent thread.
The worker thread has a CleanupStack and it creates a RFs and RFile.

The problem is killing or panicing the worker thread.
  • If the worker thread uses its own heap the cleanupstack will be deleted by the OS and the RFs and RFile will be closed.
  • If the worker thread shares its heap with the parent thread I also delete the cleanupstack on the parent thread incase the worker thread was unable to delete it itself. This works fine until i add a RFs and RFile to the cleanupStack, then I get a KERN-EXEC 0 since the handles for the RFs and RFile are only valid on the worker thread.


Is it possible to register a cleanup/exit function that will run by the worker thread incase of a kill/terminate/panic/other error that can delete the cleanupstack and then the RFs and RFile on the cleanupstack?
Should I not share the heap with the parent thread and use some other mechanism to share data between the threads?