Under the platform of Windows thread synchronization

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Primer:

In the past few days to write a Windows Phone on the platform of service, because the Windows phone kernel is based on the Windows NT, this also means that the Service code and the Win32 write Windows Phone closer to the.

Although the function of small, but once the release out, like water poured out, if my code out of the Bug, the user can access only to update the firmware update, the pressure is very large.

The main concern is the thread synchronization:

Code register a system event, when the system trigger events, called event corresponding callback function, the callback and main threads are not in the same thread, naturally led to thread synchronization.

Simply turn the "Windows via C++", review the basics of the thread synchronization code, written with foreigners to discuss, there are some details, I record it, in order to consolidate and review.

The essence of thread synchronization is to ensure a certain variable was still maintain consistency of multiple threads access time.

The user mode thread synchronization:

There are several synchronous mode, user mode:

Also pay attention to the:

The use of kernel object is thread synchronization:

The kernel objects include: Process, thread, file, timer, event, semaphore, mutex. And there areThe trigger / not trigger Two kinds of state. Kernel object can be represented by the Handle type.

Note: all kernel object after use should be closed by CloseHandle


This is consistent with the Win32 platform written, only mobile phone resources more nervous, always considering the power consumption.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Alston at December 03, 2013 - 11:23 AM