C mmap()和pthreads-复制VMA
IC mmap()和pthreads-复制VMA,c,linux-kernel,pthreads,mmap,C,Linux Kernel,Pthreads,Mmap,Immap()匿名VMA。pthreads如何处理这个VMA? 我希望为每个线程复制vma及其内存。为此我需要哪些旗帜 I mmap()匿名VMA。pthreads如何处理这个VMA “pthreads”(Linux中线程的用户空间库)对来自mmap的新VMA没有特殊处理 我希望为每个线程复制vma及其内存 不能,因为单个进程的每个线程都有相同的VMA glibc中的默认pthread实现—NPTL使用带有clone\u VM标志的clonesyscall: 并说: 因此,在LinuxGlib
mmap()
匿名VMA。pthreads如何处理这个VMA?
我希望为每个线程复制vma及其内存。为此我需要哪些旗帜
I mmap()匿名VMA。pthreads如何处理这个VMA
“pthreads”(Linux中线程的用户空间库)对来自mmap的新VMA没有特殊处理
我希望为每个线程复制vma及其内存
不能,因为单个进程的每个线程都有相同的VMA
glibc中的默认pthread实现—NPTL使用带有clone\u VM
标志的clone
syscall:
并说:
因此,在LinuxGlibcPthreads中,进程的所有线程都可以看到通过一个线程使用mmap(2)或munmap(2)执行的任何内存映射或取消映射。mmap不需要附加标志;CLONE\u VM标志已提供给CLONE。谢谢您的回答。这是一个皮蒂,我以为有一个标志会复制记忆。就像被复制的堆栈一样,线程之间不需要复制内存;它们都有共同的内存空间。不同进程之间共享内存的MMAP_…@tobawo:堆栈也不会被复制-为每个新pthread创建一个新堆栈(位于新的虚拟地址)。“…Linux中线程的用户空间库…”。pthreadapi不是特定于Linux的接口,相反,许多兼容POSIX的操作系统都有可用的pthreadapi。POSIX线程是POSIX定义的标准API。1c@FehmiNoyanISI,问题是关于linux(linux内核),而glibcs libpthread(nptl)是某个东西的linux实现。它使用linux特定的克隆系统调用。POSIX线程api可能以其他方式在其他操作系统中实现,但linux api/abi是最流行的一种。而且几乎没有其他针对linux的POSIX线程的活实现。
47 static int
48 create_thread (struct pthread *pd, const struct pthread_attr *attr,
49 bool stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran)
50 {
66 /* We rely heavily on various flags the CLONE function understands:
67
68 CLONE_VM, CLONE_FS, CLONE_FILES
69 These flags select semantics with shared address space and
70 file descriptors according to what POSIX requires.
94 const int clone_flags = (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SYSVSEM
95 | CLONE_SIGHAND | CLONE_THREAD
96 | CLONE_SETTLS | CLONE_PARENT_SETTID
97 | CLONE_CHILD_CLEARTID
98 | 0);
99
102 if (__glibc_unlikely (ARCH_CLONE (&start_thread, STACK_VARIABLES_ARGS,
103 clone_flags, pd, &pd->tid, tp, &pd->tid)
CLONE_VM (since Linux 2.0)
If CLONE_VM is set, the calling process and the child process
run in the same memory space. In particular, memory writes
performed by the calling process or by the child process are
also visible in the other process. Moreover, any memory
mapping or unmapping performed with mmap(2) or munmap(2) by
the child or calling process also affects the other process.