Thread-related functions:
1. header file of pthread-related functions:
# Include <pthread. h>
2. pthread creation function:
Int pthread_create (pthread_t * thread_id, const pthread_attr_t * attributes, void * (* thread_function) (void *), void * arguments );
3. The ending function corresponding to pthread:
Int pthread_exit (void * status );
4. One thread can wait for the end of another thread:
Int pthread_join (pthread_t thread, void ** status_ptr );
5. Get the id of the current thread:
Pthread_t pthread_self ();
6. Compare thread id:
Int pthread (pthread_t t1, pthread_t t2 );
The mutex has two basic operations: Lock and unlock. There are five basic functions used to manage mutex:
1. int pthread_mutex_init (pthread_mutex_t * mut, const pthread_mutexattr_t * attr );
2. int pthread_mutex_lock (pthread_mutex_t * mut );
3. int pthread_mutex_unlock (pthread_mutex_t * mut );
4. int pthread_mutex_trylock (pthread_mutex_t * mut );
5. int pthread_mutex_destroy (pthread_mutex_t * mut );
Condition variable
1. int pthread_cond_init (pthread_cond_t * cond, pthread_condattr_t * attr );
2. int pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mut );
3. int pthread_cond_signal (pthread_cond_t * cond );
4. int pthread_cond_broadcast (pthread_cond_t * cond );
5. int pthread_cond_timedwait (pthread_cond_t * cond, pthread_mutex_t * mut, const struct timespec * abstime );
6. int pthread_cond_destroy (pthread_cond_t * cond );