Thread
Light weight process
-
context switching overhead가 줄어듦
-
process와 자원을 공유함 -> 동기화가 힘듦
- 자원: file descriptor, memory
-
thread 중 하나가 exec를 실행하면 모든 thread가 종료됨
-
thread 중 하나가 fork를 실행하면 해당 thread만 복제됨
-
함수
- pthread_t pthread_self()
- 본인 thread 정보를 가져옴
- pid_t gettid()
- 커널에서 관리하는 tid를 가져옴
- pthread_t pthread_self()
- join
- joinable thread
- 기본적인 thread
- join이 가능하고 꼭 join을 해야함
- 안 하면 리소스 해제가 안 됨 - zombie thread
- detached thread
- join 없이 종료
- pthread_detach - 호출 측에서
- joinable thread
- attribute: thread의 특성을 설정
- pthread_attr_init() - 생성
- pthread_attr_setdetachstate()
- pthread_attr_setstackszie()
- pthread_create 할 때 적용 가능
- pthread_attr_destroy() - 해제