Turn off multi-threaded NSDocument

I have a Cocoa application based on NSDocument, and I have several minor threads that I need to legitimately stop (waiting for them to execute through the current loop) when users close the document window or when the application terminates, I use canCloseDocumentWithDelegate to send the flag to flows when the document is closed, and then when they are completed, one of them calls [NSDocument close]. This seems to work strong when the user closes the document window, but when you exit the application, everything happens wrong (crash before he calls something). What is the right procedure for something like that?

+3
source share
1 answer

The best way is for the threads to own the objects needed to complete the thread, doing whatever it does, until it can stop processing and shut down as quickly as possible.

In non-GC, this means -retainthat the stream -releaseis complete. For GC, this is simply a solid reference to the desired object (s).

If there is any lengthy processing that should continue and should complete before the document is closed, then discard the progress bar and leave the document modal until completed (both Aperture and iPhoto do just that).

+4
source

Source: https://habr.com/ru/post/1733953/


All Articles