Win Thread Synchronization Summary

Source: Internet
Author: User
Tags mutex

1. Atomic operation
Used for synchronization of general single variables.
Lock a variable with the associated API
such as: InterlockedIncrement (&n)
Https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-interlockedincrement
2. Critical section is an upgrade lock code block for atomic operations
Between EnterCriticalSection and LeaveCriticalSection
https://msdn.microsoft.com/en-us/library/ms684169 (v=vs.85). aspx
3. Mutex critical zone upgrade for more than one process mutex
CreateMutex Creating locks
OpenMutex Open the lock, which means the other process can't come in.
The ReleaseMutex release lock is not related to the mutex.
Switch back and forth by using WaitForSingleObject.
Way:
When a mutex is created it is in the excited state. That is, the lock is open.
When any one thread process calls the WaitForSingleObject, it returns immediately so that it is in a non-excited state. Indicates being occupied. By the parameters or ReleaseMutex to be released.
Https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=ZH-CN&k=k (mfcapplication1dlg% 2FWaitForSingleObject); K (WaitForSingleObject); K (devlang-c%2b%2b); K (targetos-windows) &rd=true
4. The semaphore is multiple locks can be
5. Event is the most advanced can manually change his excited state and non-excited state. CreateEvent
Https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=ZH-CN&k=k (mfcapplication1dlg% 2FCreateEventW); K (createeventw); K (devlang-c%2b%2b); K (targetos-windows) &rd=true

Win Thread Synchronization Summary

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.