简体   繁体   English

sysCall(Sys_gettid) 返回 -1

[英]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.

相关问题 iOS使用什么函数/系统调用来读写文件 - What function/syscall is used by iOS to read and write files 如何在iOS 8.3中调试syscall_thread_switch? - How to debug syscall_thread_switch in iOS 8.3? 对“iPhoneSimulator”使用 sys root,但在 NPM 安装中针对“MacOSX”警告 - using sys root for 'iPhoneSimulator' but targeting 'MacOSX' warning in NPM install syscall_thread_switch iOS 8.3 竞赛 - CocoaLumberjack 错误? 如何调试这个? - syscall_thread_switch iOS 8.3 race - CocoaLumberjack bug? how to debug this? 观看文件更改时出错:EMFILE {“code”:“EMFILE”,“errno”:“EMFILE”,“syscall”:“查看文件更改时出错:”,“filename”:null}? - Error watching file for changes: EMFILE {“code”:“EMFILE”,“errno”:“EMFILE”,“syscall”:“Error watching file for changes:”,“filename”: null}? 必须先从模块“ Darwin.POSIX.sys.xattr”导入“ setxattr”的声明 - Declaration of ‘setxattr’ must be imported from module ‘Darwin.POSIX.sys.xattr’ before it is required ABRecordCopyValue返回0吗? - ABRecordCopyValue return 0 ? UITableViewAutomaticDimension返回-1 - UITableViewAutomaticDimension return -1 错误-缺少预期返回&#39;UIInterfaceOrientationMask&#39;的函数中的返回 - Error - Missing return in function expected to return 'UIInterfaceOrientationMask' 在预期会迅速返回的函数中缺少返回 - missing return in a function expected to return swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM