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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3114c-2bd5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3114c-2bd5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?