Skip to content

πŸͺŸ Windows system programming from the perspective of synchronous and asynchronous Input/Output.

License

Notifications You must be signed in to change notification settings

gunh0/windows-system-programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Windows System Programming

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.


Visual Studio Setting

  • In Solution 'WindowsSystemProgramming' Propertry Pages
  • 'Current selection' Check
  • Build & Run


1. Synchronization

1-1. Thread & Synchronization

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




1-2. Synchronization with Kernel Objects

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




1-3. User Mode Synchronization

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

About

πŸͺŸ Windows system programming from the perspective of synchronous and asynchronous Input/Output.

Topics

Resources

License

Stars

Watchers

Forks