Lin*_*ini 1 c multithreading bsd
有谁知道在 BSD 上以整数形式获取当前线程 ID 吗?
我找到了这个
#ifdef RTHREADS
299 STD { pid_t sys_getthrid(void); }
300 STD { int sys_thrsleep(void *ident, int timeout, void *lock); }
301 STD { int sys_thrwakeup(void *ident, int n); }
302 STD { int sys_threxit(int rval); }
303 STD { int sys_thrsigdivert(sigset_t sigmask); }
#else
299 UNIMPL
300 UNIMPL
301 UNIMPL
302 UNIMPL
303 UNIMPL
#endif
Run Code Online (Sandbox Code Playgroud)
并尝试了(长)syscall(229)但不起作用(它崩溃了)。在 Linux 上,我可以通过系统调用(长)syscall(224) 获取线程 ID,它给我一个整数(通常是 4 位数字)。任何人都可以帮忙吗?谢谢。
不存在“BSD”这样的东西。每个 *BSD 系统都完全不同,尤其是在线程方面。即使在像 FreeBSD 这样的单个项目中,也存在各种 pthread 实现(libc_r、kse、thr),这些实现因操作系统版本和用户配置而异。
话虽如此,在 FreeBSD-8 上应该位于/usr/include/sys/thr.hint thr_self(long *id)中,而在相当新的 NetBSD 上应该位于/usr/include/lwp.h中。lwpid_t _lwp_self(void)
对于更多平台,您可以查看wine 源中的int get_unix_tid(void) 。