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