C ++ 11 thread synchronization

1. Thread Synchronization: critical sections, mutexes, events, semaphores

2. Thread waits: event, condition variables, while / sleep (), join

Condition variable waiting for thread and thread notification use different types of locks: https://blog.csdn.net/lijinqi1987/article/details/78425781

 

3. Thread Callback: How to switch from worker thread to the UI main thread?

4. Before the main thread exits, how to ensure that all sub-thread has quit? Multi-threaded destructor, exit the process?

When the main thread exits, the child thread access interface return has not expired yet?

 

C ++ std :: mutex is the most basic mutex provides exclusive ownership of properties, std :: mutex provides the following member functions


Constructor: std :: mutex configuration may not be copied, the copy is not allowed move, the mutex object was originally created is in the unlocked state.
lock (): calling thread will lock the mutex, thread calls this function the following three conditions occur:
(1) if the mutex is not currently locked, the thread is called the mutex lock, until calling unlock, the thread always had the lock.
(2) If the current mutex is locked by another thread, the current thread is blocked calls live.
(3) If the current mutex is currently locked calling thread, it will deadlock ,, that is not allowed to lock twice in the same thread .
unlock (): Unlock and release ownership of the mutex.
try_lock (): try to lock mutex if the mutex is occupied by other threads, the current thread will not be blocked, thread calls the function will appear the following three cases:
(1) if the current mutex is not other threads possession, the thread mutex lock, unlock until the thread calls release the mutex.
(2) If the current mutex is locked by another thread, the current calling thread returns false, and will not be blocked off.
(3) If the current mutex is currently locked calling thread, it will deadlock.
 

 

Guess you like

Origin blog.csdn.net/smartgps2008/article/details/90741675