[英]sysCall(Sys_gettid) return -1
I use sysCall(Sys_gettid) on iOS app, but return -1.我在 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;
}
You shouldn't use syscall
on iOS or macOS directly.您不应该直接在 iOS 或 macOS 上使用
syscall
。 The gettid
call is meant to get the current thread ID. gettid
调用旨在获取当前线程 ID。 Depending on what you want to do there are several alternatives:根据您要执行的操作,有几种选择:
For example, you can query the thread ID using pthreads:例如,您可以使用 pthreads 查询线程 ID:
#include <pthread.h>
uint64_t tid;
pthread_threadid_np(NULL, &tid);
You could also make use of NSThread
.您也可以使用
NSThread
。 Either use the pointer returned by [NSThread currentThread]
or, probably better, make use of the threadDictionary
:要么使用
[NSThread currentThread]
返回的指针,要么使用threadDictionary
更好:
(untested)
NSString * identifier = thread.threadDictionary[@"myIDKey"];
if (identifier == nil) {
identifier = [NSUUID UUID].UUIDString;
thread.threadDictionary["myIDKey"] = identifier;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.