進程創建線程,每個線程可以共享進程的地址空間;但同時線程需要保留一些自己私有的數據
unix中的thread獨自持有的資源:
- Stack pointer
- Registers
- scheduling properties(policy and priority)
- set of pending and blocked signals
- Thread specific data
- Changes made by one thread to shared system resources will be seen by all other threads
- Two pointers(may belong by different threads) have the same value point to the same data
- Reading and Writing to the same memory locations need explicit synchronization by programmer
- Light weight: can be created with less overhead(process: fork(); thread: pthread_creat())
- Efficient communication / Data exchange(not copy data opration, just need to pass address)