The part that threads in the same process do not share is the thread's stack.
The environment shared by threads includes: process code segments, public data of the process (using these shared data, threads can easily communicate with each other), file descriptors opened by the process, and signals The processor, the current directory of the process, and the process user ID and process group ID.
While processes have many commonalities, they also have their own personality. With these personalities, threads can achieve concurrency. These characteristics include:
1. Thread ID
Each thread has its own thread ID, which is unique in this process. Processes use this to identify threads.
2. Register group value
Since threads run concurrently, each thread has its own different running clues. When switching from one thread to another, , the state of the original thread's register set must be saved so that the thread can be restored when it is switched again in the future.
3. Thread stack
#The stack is necessary to ensure that the thread runs independently. Thread functions can call functions, and the called functions can be nested layer by layer, so the thread must have its own function stack so that the function call can be executed normally without being affected by other threads.
4. Error return code
Since there are many threads running in the same process at the same time, it is possible that a certain thread sets the errno value after making a system call, and in that process The thread has not yet processed this error, and another thread is put into operation by the scheduler at this time, so the error value may be modified. Therefore, different threads should have their own error return code variables.
5. Thread's signal masking code
Since each thread is interested in different signals, the thread's signal masking code should be managed by the thread itself. But all threads share the same signal handler.
6. Thread priority
Since threads need to be scheduled like processes, there must be parameters available for scheduling. This parameter is the priority of the thread.
The above is the detailed content of What is the part that threads in the same process do not share?. For more information, please follow other related articles on the PHP Chinese website!