Hi... > I have some threads program and the /proc/pid/maps output show the > same stack (initial and final addresses) for all running threads of > an application. According to the definition of threads, each thread > should contain its own stack, but how Linux can identify it? I think, even the addresses seem equal, physically they are different pages. IMHO this is done so that the kernel doesn't need to "tangle" with SP (stack pointer). Hm, about how to identify, IMHO there are several possibilities: 1. The threads explicitly create a memory region (VMA) and ask the kernel to assign it as the stack area. Since this is just another VMA in the same process address space, the kernel just needs to update the SP(Stack Pointer) to initially point to this VMA when the thread is selected to run 2. The thread doesn't explicitly ask for a thread stack. Here, the kernel marks the parent process's stack as COW. As soon as the new thread uses (i.e write) the stack, copy-on-write happens and the kernel automatically setups new page frames as the stack. Of course, PTE (Page Table Entry)-s are updated as well. Here, I think SP is still the same since basically the virtual address doesn't change. > Does thread in Linux contain its own stack? IMHO yes, because if it doesn't, local variables and stack frames will mix and that's bad. > Since Linux kernel does not provide an explicit support for threads, > the stack can be a shared resource among threads, right? I think, theoritically it can, as long as it doesn't either declare or allocate local variables or do function call, since both utilize stack. Ehm wait, maybe if the thread uses TLS (Thread Local Storage), then stack won't be needed. But, I am not sure. regards, Mulyadi -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/