z

BLOG ARTICLE 2016/03 | 2 ARTICLE FOUND

  1. 2016.03.16 Glance - GlancePlus system performance monitor for HP-UX
  2. 2016.03.15 pthread

Glance - GlancePlus system performance monitor for HP-UX

 

AND

pthread

개발 2016. 3. 15. 09:40

 

/*

pthread_t는 시스템 마다 형식이 다름 HP의 경우 int

계속 증가하다 최대값에 도달 시 다시 n(남은스레드 + 1) 부터 시작

*/

pthread_t tid;

 

pthread_create(&tid, NULL, ThreadFunc, (void*)&param);

pthread_join(pthread_t tid, void ** thread_return);

pthread_exit(void * rval); //스레드에서 자신 종료 - rval은 join에 보낼 리턴값.

pthread_cancel(tid); //특정스레드를 죽임

pthread_kill(pthread_t tid, int sig); //특정 스레드에 시그널 보냄. (단, 해당 프로세스 전체에 영향이 감으로 스레드 죽일 때는 부적합) 스레드가 살아 있는지 확인용도로 사용

pthread_kill(tid, 0) -> 리턴값이 ESRCH이면 존재하지 않는 스레드.

pthread_detach(tid); //스레드 분리 - 해당 스레드가 죽으면 별도 join없이 자원 정리

pthread_cleanup_push(void (*func)(void*), void * arg); //스레드 종료 핸들러 등록 (스택으로 쌓임

pthread_cleanup_pop(int execute); //등록된 핸들러 삭제.

 

pthread_mutex_init(&g_mutex, NULL);  //뮤텍스 초기화
pthread_cond_init(&g_condition, NULL); //조건변수 초기화

 

pthread_mutex_lock(&g_mutex); //뮤텍스 락
pthread_cond_signal(&g_condition); //waiting 중인 스레드를 한 넘을 깨움
pthread_cond_broadcast(&g_condition); //waiting 중인 스레드 모두 깨움
pthread_mutex_unlock(&g_mutex); //뮤텍스 언락

pthread_cond_destroy(&g_condition); //조건변수 파괴
pthread_mutex_destroy(&g_mutex); //뮤텍스 파괴

 

void f(){

 

  pthread_mutex_lock(&g_mutex);

  pthread_cond_wait(&g_condition, &g_mutex);

  //wake up...do work...

  pthread_mutex_unlock(&g_mutex); //뮤텍스 언락

 

}

 

void sender(){

 

  pthread_mutex_lock(&g_mutex);
  pthread_cond_signal(&g_condition);
  pthread_mutex_unlock(&g_mutex); //뮤텍스 언락

 

}

 

Thread Pool Example

 

 

https://sourceforge.net/projects/cthreadpool/

 

 

 

 

AND