728x90
Thread cancellation
- thread가 완료 되지 않았을 때 cancel하는 system call
- pthread_cancel(pthread_t tid)
cancellation types
- asynchronous cancellation
- 어떤 thread를 종료하기 위해 호출하면 즉시 종료된다.
- 만약에 대상 thread가 현재 cancel요청이 왔을 때 resource는 바로 반환을 한다.
- deferred cancellation
- 현재 자신의 일을 수행완료한 다음에 종료한다.
- 그 thread는 특정 point에서 종료된다.
- pthread_testcancel()를 호출하여 cancel point를 만들어서 check한다.
- pthread_cleanup_push()를 호출하여 cancel point에서 register를 clean한다.??
int pthread_setcancelstate(int state, int *oldstate);
int pthread_setcanceltype(int type, int *oldtype);
두가지 함수를 통해서 특정 thread에 대해서 cancel state와 type을 정해준다. |
state : cancel 가능한가 enable / disalbe oldstate : 기존의 이전 state가 어떤 것이었는지 ![]() |
return |
Dangerous Argument Passing
int rc, i;
for(i=0; i < NUM_THREADS;i++) {
printf("Creating thread %d\n", i);
rc = pthread_create(&threads[i], NULL, routine, (void *) &i);
...
}
implicit sharing 암묵적인 공유
- 현재 thread와 새로운 thread에서 i값이 공유되고 있다.
- 새로운 thread에서 i값이 변경되어서 오류가 발생할 수 있다.
- 흔히 하는 실수니 조심하자
728x90
'시스템 프로그래밍' 카테고리의 다른 글
시스템 프로그래밍 7장 - Thread : Condition variable (0) | 2020.05.06 |
---|---|
시스템 프로그래밍 6장 - Thread : Synchronization (0) | 2020.05.06 |
시스템 프로그래밍 6장 : Thread (0) | 2020.05.06 |
시스템 프로그래밍 5장 - Process Control : Daemon (0) | 2020.05.05 |
시스템 프로그래밍 5장 - Process Control : Process Start & Exit (0) | 2020.05.05 |