PThread learning notes

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.