My NSThread’s selector is a wrapper for a potentially long-running C++ method. I want the thread to respond to the - cancel message, which requires checking in with the NSThread object itself and asking if it isCancelled.
How can my C++ code send messages to the NSThread it’s running on?
My NSThread’s selector is a wrapper for a potentially long-running C++ method. I want
Share
Exactly the same way as any in Objective C or pure C code, assuming you’re using Objective C++ code (the .mm extension, by default, compiles as Objective C++). Then just use
[[NSThread currentThread] isCancelled]inside your C++ code to check the thread cancellation status.The restrictions on the interface between Objective C and C++ given by Objective C++ are outlined rather well at http://en.wikipedia.org/wiki/Objective-C#Objective-C.2B.2B.