Mac/iPhone: Is there a way to get a thread identifier without using Objective-C?

前端 未结 4 1313
南旧
南旧 2021-02-02 16:40

Is there a way to get any kind of thread identifier of the currently running thread without resorting to Objective-C\'s NSThread.

I\'m improving our custom debug tracing

4条回答
  •  清酒与你
    2021-02-02 17:08

    I found a one way that is enough to get some kind of unique identifier for trace output.

    pthread_mach_thread_np can be used to get a thread identifier, an unsigned int on iPhone.

    mach_port_t tid = pthread_mach_thread_np(pthread_self());
    

    Apparently this is a same thread id that is used in NSLog output.

提交回复
热议问题