[Linux Programming] Thread - 线程

[Linux Programming] Thread - 线程

#include <pthread.h>
int pthread_create(pthread_t *thread, pthread_attr_t *attr, void
*(*start_routine)(void *), void *arg);
// @attr: almost is NULL

void pthread_exit(void *retval);
// @retval: thread exit return value

int pthread_join(pthread_t th, void **thread_return);
// @thread_return: catch thread return

int pthread_cancel(pthread_t thread);
int pthread_setcancelstate(int state, int *oldstate);
// @state
// - PTHREAD_CANCEL_ENABLE / PTHREAD_CANCEL_DISABLE
// @oldstate: set NULL if you are not interested.
int pthread_setcanceltype(int type, int *oldtype);
// @type
// - PTHREAD_CANCEL_ASYNCHRONOUS / PTHREAD_CANCEL_DEFERRED
// @oldtype: set NULL if you are not interested.

int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
// @detachstate
// - PTHREAD_CREATE_JOINABLE(default) / PTHREAD_CREATE_DETACHED / ...
int pthread_attr_destroy(pthread_attr_t *attr);

int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t 
*mutexattr);
int pthread_mutex_lock(pthread_mutex_t *mutex));
int pthread_mutex_unlock(pthread_mutex_t *mutex);
int pthread_mutex_destroy(pthread_mutex_t *mutex);
// ...

-D_REENTRANT
-lpthread
#include <semaphore.h>
int sem_init(sem_t *sem, int pshared, unsigned int value);
int sem_wait(sem_t * sem);
int sem_post(sem_t * sem);
int sem_destroy(sem_t * sem);

发表评论

电子邮件地址不会被公开。必填项已用 * 标注