在Linux上,请
pthread使用
clone带有特殊标志的syscall
CLONE_THREAD。
查看文档的
clone系统调用。
CLONE_THREAD(从Linux 2.4.0-test8开始)
如果设置了CLONE_THREAD,则将子级与调用进程放在同一线程组中。为了使CLONE_THREAD讨论的其余部分更具可读性,术语“线程”用于指代线程组中的进程。
线程组是Linux 2.4中添加的一项功能,用于支持 共享单个PID
的一组线程的POSIX线程概念。在内部,此共享PID是线程组的所谓线程组标识符(TGID)。从Linux
2.4开始,对getpid(2)的调用将返回调用者的TGID。
实际上,由于POSIX.1要求线程共享相同的进程ID
,因此Linux确实更改了其线程实现。
In the obsolete LinuxThreads implementation, each of the threads in aprocess
has a different process ID. This is in violation of the POSIX
threads
specification, and is the source of many other nonconformances to the
standard; see pthreads(7).



