Windows system programming from the perspective of synchronous and asynchronous Input/Output.
Windows system programming is a programming field closely related to the Windows operating system.
In this field, you can develop various software by understanding and utilizing the internal structure and functions of the Windows operating system.
Through this, you can implement higher performance and functionality at the operating system level.
In addition, Windows system programming is closely related to hardware, so it is possible to understand the operation principle of the hardware and implement the interface between hardware and software.
With these attractive aspects, Windows system programming has become a field where you can develop more efficient and high-performance software based on a deep understanding of the operating system and hardware.
- In Solution 'WindowsSystemProgramming' Propertry Pages
- 'Current selection' Check
- Build & Run
Windows system elements required for thread synchronization
Concepts and Needs of Synchronization
- Elements of Synchronization
- Scheduling processes, Kernel objects, Threads, Thread scheduling
- Thread Programming Pattern
Thread
鈹斺攢1. CreateThread
鈹斺攢2. ThreadExcept
鈹斺攢3. MyThread
- Thread Synchronization
- The Meaning and Necessity of Synchronicization from the Perspective of Atomicity and Instruction Reordering
Instruction Reordering
鈹斺攢4. InterLock
鈹斺攢5. MemBarrier
Describes the sync wait functions and sync-only kernel objects provided by Windows
Usefulness and utilization of threads or window messages
- Thread Synchronization API
- Description of the standby function that waits for threads to synchronize
- Understand the relationship between the standby function and the kernel object
Thread Waiting Functions
鈹斺攢6. WaitThread
鈹斺攢7. MyThread2
鈹斺攢8. WaitMultiThreads
- Synchronization objects for data protection
- Describe Mutex and Semaphore from the perspective of protection of shared resources
Mutex
Mutually exclusive access
鈹斺攢9. MutexTest
鈹斺攢10. MutexNoti
Semaphore
Mutexes provide exclusive access to a shared resource, while semaphores control access to a pool of resources.
鈹斺攢11. SemaphoreTest
鈹斺攢12. TPSemaphore : Thread Pool Using Semaphore
鈹斺攢13. WQSemaphore : Waitable Queue
- Synchronization object for flow control
- Description of synchronization-only objects for the purpose of controlling and notifying flows between threads.
Event
鈹斺攢14. ExitWithEvent
鈹斺攢15. MyThread3
鈹斺攢16. EventTest
鈹斺攢17. MultiSyncWaits
Using Events as Signaling Mechanisms
鈹斺攢18. EventNotify
鈹斺攢19. WQNotify
鈹斺攢20. EventNotify2
Using Events for RW Lock
鈹斺攢21. EvtRWLock
鈹斺攢22. EvtRWLock2
Waitable Timer
鈹斺攢23. WaitableTimerTest
鈹斺攢24. WaitableTimerTest2
鈹斺攢25. ManualWTTest
鈹斺攢26. WakeSleepSystem
鈹斺攢27. SetWaitableTimerEx
- Notification
- Additional means and methods for synchronization in terms of notification, which can provide more flexibility in implementing synchronization, along with the mutex, semaphore, event, and waitable timer, all of which are dedicated synchronization objects.
Integration of Thread and Message Queue
鈹斺攢28. MsgNotify
鈹斺攢29. MsgQueue
鈹斺攢30. MsgWaitMulti
Combining with Callback Functions
鈹斺攢31. WaitPool
.NET BackgroundWorker
鈹斺攢32. BackgroundWorker
Windows provides various synchronization kernel objects that operate in kernel mode, as well as synchronization objects and APIs that operate in user mode.
In user mode, a combination of spin lock and kernel-mode switching or a separate method is used for synchronization.
Therefore, one of the advantages of user-mode synchronization is its speed.
By minimizing the switch to kernel mode, thread context switching can also be reduced, making it faster than synchronization using kernel objects.
-
Critical Section
-
A critical section is a block of code that must be executed atomically, which means that only one thread can execute it at a time. The purpose of a critical section is to prevent race conditions, which occur when two or more threads access shared resources simultaneously and interfere with each other's operations.
-
In Windows, a critical section is a user-mode synchronization object that provides a lightweight and efficient way of protecting shared resources. It works by using a spin lock mechanism, which means that a thread repeatedly checks if the critical section is available until it can acquire it.
-
To use a critical section, a thread must first call the InitializeCriticalSection function to create it. Then, the thread can enter the critical section by calling the EnterCriticalSection function and leave it by calling the LeaveCriticalSection function. If a thread tries to enter a critical section that is already locked by another thread, it will be blocked until the critical section becomes available.
-
Critical sections are a useful synchronization mechanism for protecting small sections of code that access shared resources frequently. However, they are not suitable for protecting resources that are accessed infrequently or for long periods of time, as they can cause excessive spinning and waste CPU cycles. In these cases, more heavyweight synchronization mechanisms, such as mutexes or semaphores, should be used instead.
-
Using Critical Section
鈹斺攢33. LockAccount
鈹斺攢34. CriticalSectionAccount
鈹斺攢35. CriticalSectionTest
鈹斺攢36. MyCSLock