POSIX thread memory visibility

Source: Internet
Author: User

Memory visibility between threads
    • When a thread calls a thread--create, the memory value it can see is also what its established threads can see. Any data that is written after a call to fear thread_create may not be seen by the established thread, even if the write operation occurs before a new thread is started.
    • The memory data that is seen when the line threads unlocked the mutex can also be seen by threads that are subsequently locked (or locked by waiting for a condition variable) of the same mutex. Similarly, the data written after the mutex is unlocked does not have to be seen by other threads, even if the write operation occurs before other thread lock mutexes.
    • The memory data that is seen when a thread terminates (or by canceling an operation, or returning from a startup function, or calling Pthread_exit) can also be seen by other threads that connect to that thread. Of course, the data written after termination is not seen by the connection thread, even if the write operation occurs before the connection.
    • The memory data seen by the line Cheng signal or broadcast condition variable is also seen by other threads that can be awakened. The data written after the signal or broadcast is not seen by the thread that wakes up, even if the write operation occurs before the threads are awakened.

Correct example:

Pthread_mutex_lock (&mutex1)    1;     2 ;p thread_mutex_unlock (&mutex1) pthread_mutex_lock (&mutex1)     = Variablea;/* Variablea = 1    *= variableb;/* Variablea = 2 */pthread_mutex_unlock (&mute X1)

Error Example:

Pthread_mutex_lock (&mutex1)    1;p thread_mutex_unlock (&mutex1)     2;p thread_mutex_lock (&mutex1)    = Variablea;/* Variablea = 1 *    / = Variableb;/* Variablea = 2 */pthread_mutex_unlock (&mutex1)

POSIX thread memory visibility

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.