How do I know if the current thread was created as NSThread?
I am getting C ++ callbacks from a purchased media text SDK library that creates multiple threads internally.
In particular, I get callbacks when the library wants to log a message. Sometimes I am called in the context of some NSThread that has an Autorelease pool, but sometimes I am called from other threads that do not have an Autorelease pool. Some of the calling streams are real time streams (audio capture, etc.), so performance is important.
How can I distinguish between situations where I am called in an NSThread (application main thread or other NSThreads) and only "C ++" internal threads created by the SDK library?
Nothing in the Apple documentation tells me what happens when I use
[NSThread currentThread]
when I am in the context of a different type of thread, and what happens when I call pthreadSelf (), or a similar API, on the NSThread.
Also, I'd love to hear ideas on combining abstract pools with these internal threads, if possible, and draining them from time to time.
Thank.
source to share
NSThread
is a wrapper on top of pthread, so pthread_self
will always return a valid thread object if the thread was created using APIs NSThread
, pthread, GCD, or C ++!
[NSThread currentThread]
will also return an object NSThread
, even if the stream was not created using the API NSThread
and using the public API, it is impossible to say that the returned object is just a proxy or "actual" NSThread
.
You can use a directive @autoreleasepool
to create a lightweight autoresist pool.
source to share