Reputation: 300
I need check whether pthread_t is main thread. I want do it from current thread (not from pthread_t which I need check and not from main thread).
My code (pt is pthread_t)
NSThread *thread = CFBridgingRelease(pt); // it works wrong
bool isMain = thread.isMainThread;
But I can't right convert pthread_t to NSThread.
How I can convert pthread_t to NSThread?
Or how I can check whether pthread_t is main thread?
Upvotes: 4
Views: 460
Reputation: 181824
There is no documented way to obtain an NSThread
object for a thread identified by a pthread_t
, so if ...
I need check whether pthread_t is main thread.
... is really what you need to do then you are probably up a creek.
Some of the possible alternatives are
NSThread
instead of pthreads altogether;pthread_t
identifier is recorded somewhere where you can access it for comparison; andNote also that NSThread
-- at least the one I think you mean -- is an Apple thing. If you want something more broadly portable then NSThread
is a non-starter.
Upvotes: 0