Computers/Linux System Programming

ch11. Threads

emzei 2013. 6. 16. 10:57

[스레드 식별]

  pthread_equal

#include<pthread.h>

 pthread_equal(pthread_t tid1, pthread_t tid2);

(ret)   둘이 같으면 0 이 아닌값, 같지 않으면 0

 

 

  pthrerad_self

#include<pthread.h>

 int pthread_self(void);

(ret)  호출한 스레드의 스레드 아이디

 

[스레드 생성]

  pthread_create

#include<pthread.h>

 pthread_create(pthread_t *restrict tidp, const pthread_attr_t *restrict attr,

void *(*start_rtn)(void*), void *restrict arg);

(ret)  success : 0

   failed : 오류번호
 

(ㅇㅖ)


err = pthread_create(&ntid, NULL, thr_fn, NULL);

attr과 arg는 대게 비워둠.

 

즉, 주로 pthread_create( &tid, NULL, 함수명, NULL); 식으로 사용.

 

 

[스레드 종료]

   pthread_exit

#include<pthread.h>

 void pthread_exit(void *rval_ptr);

 


  pthread_join : 스레드의 종료를 대기하는 함수

#include<pthread.h>

 int pthread_join(pthread_t thread, void **rval_ptr);

(ret)  success : 0

   failed : 오류번호

 

 *** pthread_ join( 대기할 스레드 tid,  리턴된 시작주소가 있는 곳의 주소-2중 포인터 )

 *** 반환값 안쓸땐 rval_ptr에 NULL ::: 스레드를 기다리지만, join함수의 리턴값만 회수하고, 중지상태는 회수 안함

 

 

 


[스레드 취소]

  pthread_cancel : 다른 스레드의 취소를 요청

#include<pthread.h>

 int thread_cancel(pthread_t tid);

(ret)  success : 0

   failed : 실패 시 오류 번호

 


[스레드 종료 시 호출되는 함수를 처리하는 함수]

  pthread_cleanup_push   ... callback func()

#include<pthread.h>

 void pthread_cleanup_push(void(*rtn)(void *), void *arg); 

 

  pthread_cleanup_pop

#include<pthread.h>

void pthread_cleanup_pop(int execute);

*** execute : 0인 경우 : pop한 함수 버리고 끝
*** execute : 0이 아닌 경우 : pop한 함수 수행


[스레드 분리상태]

  pthread_detach : 실행중인 스레드를 분리상태로 만듬

#include<pthread.h>

 int pthread_detach(pthread_t tid);

(ret)  success : 0

   failed : 오류 번호

 

*** 분리되면 join으로 스레드 종료 기다릴 수 없음

'Computers > Linux System Programming' 카테고리의 다른 글

ch13. Daemon process  (0) 2013.06.16
ch10. signal  (0) 2013.05.20
+ ch9. ( addition) process relationship  (0) 2013.05.20
ch9. process relationship  (0) 2013.05.20
ch8. process control  (0) 2013.04.28