gpt4 book ai didi

ios - sysCall(Sys_gettid) 返回 -1

转载 作者:行者123 更新时间:2023-11-29 05:21:31 25 4
gpt4 key购买 nike

我在 iOS 应用程序上使用 sysCall(Sys_gettid),但返回 -1。

const char *elog_port_get_t_info(void) {
static char cur_thread_info[10] = { 0 };

snprintf(cur_thread_info, 10, "tid:%04ld", syscall(SYS_gettid));

return cur_thread_info;
}

最佳答案

您不应直接在 iOS 或 macOS 上使用syscallgettid 调用旨在获取当前线程 ID。根据您想要做什么,有几种选择:

例如,您可以使用pthreads查询线程ID:

#include <pthread.h>
uint64_t tid;
pthread_threadid_np(NULL, &tid);

您还可以使用NSThread。要么使用 [NSThread currentThread] 返回的指针,或者可能更好,使用 threadDictionary :

(untested)
NSString * identifier = thread.threadDictionary[@"myIDKey"];
if (identifier == nil) {
identifier = [NSUUID UUID].UUIDString;
thread.threadDictionary["myIDKey"] = identifier;
}

关于ios - sysCall(Sys_gettid) 返回 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58643784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com