POSIX 쓰레드 함수들
#include <pthread.h>
POSIX 쓰레드
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void * arg);
int pthread_join(pthread_t th, void **thread_return);
int pthread_detach(pthread_t th);
void pthread_exit(void *retval);
pthread_t pthread_self(void);
다른 쓰레드의 종료
int pthread_cancel(pthread_t thread);
int pthread_setcancelstate(int state, int *oldstate);
PTHREAD_CANCEL_ENABLE : 취소허용
PTHREAD_CANCEL_DISABLE
int pthread_setcanceltype(int type, int *oldtype);
PTHREAD_CANCEL_ASYNCHRONOUS : 바로 종료
PTHREAD_CANCEL_DEFERRED : 세마포어, JOIN, 뮤텍스등의 대기점에서 벗어나면 종료
void pthread_testcancel(void);
뮤텍스
int pthread_mutex_init(pthread_mutex_t * mutex, const pthread_mutex_attr *attr);
pthread_mutex_t a_mutex = PTHREAD_MUTEX_INITIALIZER; 와 같이 상수를 사용해 초기화를 할 수도 있다.
int pthread_mutex_destory(pthread_mutex_t *mutex);
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
잠글 수 없을때 대기하는것이 아닌 에러를 바로 리턴함.
int pthread_mutex_unlock(pthread_mutex_t *mutex);
조건변수 : 대기중인 쓰레드를 깨운다. 임의의 하나만 깨움.
int pthread_cond_init(pthread_cond_t *cond, const pthread_cond_attr *attr);
pthread_cond_t cond = PTHREAD_COND_INITIALIZER; 와 같이 초기화를 할 수도 있다.
int pthread_cond_signal(pthread_cond_t *cond);
int pthread_cond_broadcast(pthread_cond_t *cond);
int pthread_cond_wait(pthread_cond_t cond, pthread_mutex_t *mutex);
int pthread_cond_timedwait(pthread_cont_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime);
int pthread_cond_destroy(pthread_cond_t *cond);