The question of whether a thread has its own memory space

from a thread and process point of view, a process is the smallest unit of resource allocation, and a thread is the smallest unit of independent scheduling.
multiple threads in the same process can execute concurrently, sharing process resources.
Thread does not own resources, it can access resources that belong to the process, the process has its own independent space address, the thread does not have its own independent space address, but the thread has its own stack and local variables.

how to understand that threads do not have a separate address space but threads can have private stacks, program counters, and local method areas.

it has always been my understanding that the thread"s stack, program counter, and local area are also stored in the process"s address space, but these stacks, program counters, and local method areas can only be accessed by a specific thread, but not by other threads.

is it right to understand this?


your understanding is correct, add a little bit, the stack of threads, other threads can also access, but not conventional access, if you use C / CPP language, after the array is out of bounds, it is easy to access the stack of other threads, which may lead to exceptions of other threads. This also proves from the side that multiple threads in a process share memory.

Menu