Linux Programming----Threading Programming

Source: Internet
Author: User

Overview:

1: The process is the smallest unit of the schedule, and is the smallest unit of resource allocation.

2: Threads in the process are shared global variables as well as memory .

3: Sharing: Instructions, removing private data, signal processing and routines, operating environment

Source: http://www.cnblogs.com/forstudy/archive/2012/04/05/2433853.html

Function Description:

Description

The ID number used to get this thread----ID is a long unsigned integer

------------------------------Split Line--------------------------------

Description

Used to determine if thread IDs are equal

------------------------------Split Line--------------------------------

Description

Creates a thread where the thread function is the thread's entrance. The thread will start when it is created.

------------------------------Split Line--------------------------------

Description

Thread Exit Function

------------------------------Split Line--------------------------------

Description

Wait for thread th to finish executing:

------------------------------Split Line--------------------------------

Description

Pthread_setcancelstate (pthread_cancel_enable,null); This function setting can be canceled by another thread
The above function allows the thread to be requested to cancel the thread.

Synchronization mode:

Mutual exclusion lock function

Mutex initialization: Pthread_mutex_init ()

Mutex Lock: Pthread_mutex_lock ()

Lock exclusion: Pthread_mutex_trylock ()

Mutex unlock: Pthread_mutex_unlock ()

Eliminate mutex: Pthread_mutex_destroy ()

semaphore function

Sem_init () creates a semaphore and initializes it

Sem_wait () and Sem_trywait (): p operation, reduce the value of the semaphore by one when the semaphore is greater than zero

Difference: If the semaphore is less than zero, sem_wait () will block the thread, and sem_trywait () will immediately return

Sem_post (): v operation, the value of the semaphore plus a simultaneous signal to wake up the waiting thread

Sem_getvalue (): Gets the value of the semaphore

Sem_destroy (): Delete semaphore

Condition variable function:

See: http://blog.chinaunix.net/uid-21411227-id-1826890.html

Initializing condition variables Pthread_cond_init

block on the condition variable pthread_cond_wait

unblock on a condition variable pthread_cond_signal

block until the specified time pthread_cond_timedwait

Free All threads that are blocked Pthread_cond_broadcast

releasing a condition variable Pthread_cond_destroy

Linux Programming----Threading Programming

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.