What is in the stream next to the stack

In a Linux process, each thread has its own stack. In addition, what else is local for each thread. I read things like a file allocation table, etc. Can someone provide me with a list of things that relate to the thread and how they are located in memory.

Secondly, I noticed that when I allocate a stack for a stream (see the code below), the address of the first variable in the stream function is somehow pretty bytes after the address of the stack that I allocated ( stackAddr ). I think this is because the top of the stack is the end address of the allocated stack memory, since the difference in the value of the local variable address and the allocated stack is approximately equal to the size of the stack ( STACKSIZE ). In other words, it looks like it is growing from bottom to top.

pthread_attr_init( &attr[tid] ); stackAddr = malloc(STACKSIZE); pthread_attr_setstack( &attr, stackAddr, STACKSIZE ); 
+7
source share
3 answers

For the first question I can think of:

  • stream id
  • Stack
  • machine registers
  • stream-dependent variables (key / value pairs specified by the storage class pthread_setspecific and __thread )
  • signal mask
  • set of pending signals
  • errno value

Secondly, yes, you're right, on x86 the stack grows to lower addresses. So, if you use pthread_attr_setstack , the area will start to be used from the end.

+6
source

Per POSIX XBD 3.396

A single control flow within the process. Each thread has its own thread identifier, scheduling priority and policy, errno value, thread-specific bindings, and the required system resources to support the control flow. Everything whose address can be determined by the thread, including, but not limited to, static variables, storage obtained through malloc (), directly addressed storage, obtained using functions defined for implementation, and automatic variables, is available for all threads in one process.

+5
source

On Linux, the application programmer has great control over which resources are private for each thread and which are shared by other threads if they prefer to use their own clone() API rather than the pthreads thread implementation.

This means that it is not possible to give a definitive answer - resources that depend on the stream depend on which flags were passed to clone() when the stream was created.

Note also that many of these resources do not live in user space — things like a signal mask are stored in the kernel.

0
source

All Articles