Win32 Multithreading Design Summary

Source: Internet
Author: User
Tags mutex

Recently read the Win32 multithreaded programming, summed up a few

The main problem with multithreading is thread synchronization, and thread invocation is implemented by the operating system, so thread synchronization must be supported by the operating system, which mentions the busy loop and the sleep structure I used before to achieve thread synchronization, when I felt like there was no other way, Until you meet the Wait series API, here's a summary of the various thread synchronization methods

1. The use of critical areas, the advantages do not need to produce system kernel objects, fast, high efficiency. Key API:

    

void InitializeCriticalSection (Lpcritical_section lpcriticalsection)//Initialize critical section

void EnterCriticalSection (Lpcritical_section lpcriticalsection)//Enter critical section

void LeaveCriticalSection (Lpcritical_section lpcriticalsection)//Exit critical section

void DeleteCriticalSection (Lpcritical_section lpcriticalsection)//release Critical Zone resources

2. Mutex, fixed a deadlock problem that cannot be solved by critical section, resulting in kernel object. Because the kernel object can be shared by multiple processes, there is no OVA with the critical API

CreateMutex WaitForSingleObject Waitformultipleobject

3. The semaphore solves the problem that a resource cannot be shared by multiple threads at the same time. Parent Set key API that can be considered a mutex

CreateSemaphore

The 4 event, which can be used by the thread itself to change the excitation state, can be utilized to design its own synchronization mechanism key API

CreateEvent

Other

Read/write control lock, interlockedincrement for a single variable, etc.

The shortcoming of the book is obvious. Not deep enough, probably only the API call, the deep-seated principle of the introduction of a few, for the development of the application is enough, to the reverse of the staff, the understanding is almost.

Still a bit wordy, to say the truth!

Win32 Multithreading Design Summary

Related Article

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.