Threads within a process use the same address space.
"variable" is the concept of a programming language. Variables disappear when the source code passes through the compiler (some can be reduced to characters).
Themes can share absolutely all memory. One thread can access any memory location of another.
The ease with which this is done depends on the programming language and basic linker support. There are very few programming languages that support real streaming support (for example, Ada-called text). Ada has explicit mechanisms that allow threads to exchange data using variables.
So then:
I am reading the operating system concept from Silberschatz 7th ed,
This is the beginning of your problem.
he says that threads of the same process share a section of code, a section of data, and other OS resources,
There are all system concepts. Many systems do not have a “Code Section” or “Data” section. There is simply memory with certain attributes (for example, read only, read / write, read / execute).
but have separate sets of stacks and registers.
Registers are a system resource that is allocated when scheduling a stream. A thread does not have its own set of registers. Each thread has its own set of register values, which are loaded when the thread is active and saved when it becomes inactive.
Stacks are just read / write memory blocks.
However, the problem is that I am working on states that threads share local variables, but are not local variables stored on the stack, so should separate threads have their own copies?
Again, threads share memory. They use "local" variables only if the programming language used supports such an exchange, or such separation occurs through an "accident."
Mapping variables to use a memory allocation type is a compiler function. FORTRAN 66/77 and COBOL usually did not allocate any variables on the stack