C ++ 11 concurrent to program four ------ share data between threads

for example:

  You just to work, only renters, too expensive to rent and others rented, two people live together there is only one toilet every morning to get up, if your roommate in the bathroom, you can only wait, if you force go, that picture will not be described. The same problem, if multiple threads share a data read and write data there, it should be noted that the share of data protection.

Use a mutex to protect shared data:

  The current access to shared data, use the mutex lock prize data, when the end of the visit, then the data is unlocked. Mutex in C ++ is one of the most common data protection mechanisms.

C ++, using a mutex:

  

Guess you like

Origin www.cnblogs.com/418ks/p/11595024.html