{"id":22271218,"url":"https://github.com/gunh0/windows-system-programming","last_synced_at":"2026-05-09T10:40:12.398Z","repository":{"id":127669113,"uuid":"264827569","full_name":"gunh0/windows-system-programming","owner":"gunh0","description":"🪟 Windows system programming from the perspective of synchronous and asynchronous Input/Output.","archived":false,"fork":false,"pushed_at":"2023-04-22T18:07:45.000Z","size":6070,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T14:18:29.797Z","etag":null,"topics":["cpp","csharp","mutex","semaphore","synchronization","thread","windows"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gunh0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-18T04:38:25.000Z","updated_at":"2023-04-22T17:43:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"b4685a13-6e7d-486f-82c7-37b86e5204d5","html_url":"https://github.com/gunh0/windows-system-programming","commit_stats":null,"previous_names":["gunh0/windows-system-programming"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gunh0%2Fwindows-system-programming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gunh0%2Fwindows-system-programming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gunh0%2Fwindows-system-programming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gunh0%2Fwindows-system-programming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gunh0","download_url":"https://codeload.github.com/gunh0/windows-system-programming/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245495418,"owners_count":20624805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","csharp","mutex","semaphore","synchronization","thread","windows"],"created_at":"2024-12-03T12:11:11.202Z","updated_at":"2026-05-09T10:40:07.355Z","avatar_url":"https://github.com/gunh0.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Windows System Programming\n\n\u003e Windows system programming from the perspective of synchronous and asynchronous Input/Output.\n\nWindows system programming is a programming field closely related to the Windows operating system.\n\nIn this field, you can develop various software by understanding and utilizing the internal structure and functions of the Windows operating system.\n\nThrough this, you can implement higher performance and functionality at the operating system level.\n\nIn 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.\n\nWith 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.\n\n\u003cbr/\u003e\n\n### Visual Studio Setting\n\n-   In Solution 'WindowsSystemProgramming' Propertry Pages\n-   'Current selection' Check\n-   Build \u0026 Run\n\n\u003cbr/\u003e\n\n\u003cbr/\u003e\n\n## 1. Synchronization\n\n### 1-1. Thread \u0026 Synchronization\n\n**Windows system elements required for thread synchronization**\n\n**Concepts and Needs of Synchronization**\n\n\u003cbr/\u003e\n\n-   **Elements of Synchronization**\n    -   Scheduling processes, Kernel objects, Threads, Thread scheduling\n    -   Thread Programming Pattern\n\n**_Thread_**\n\n└─1. [CreateThread](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/01_CreateThread/CreateThread.cpp)\n\n└─2. [ThreadExcept](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/02_ThreadExcept/ThreadExcept.cpp)\n\n└─3. [MyThread](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/03_MyThread/MyThread.cpp)\n\n\u003cbr/\u003e\n\n-   **Thread Synchronization**\n    -   The Meaning and Necessity of Synchronicization from the Perspective of **Atomicity** and **Instruction Reordering**\n\n**_Instruction Reordering_**\n\n└─4. [InterLock](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/04_InterLock/InterLock.cpp)\n\n└─5. [MemBarrier](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/05_MemBarrier/MemBarrier.cpp)\n\n\u003cbr/\u003e\n\n\u003cbr/\u003e\n\n---\n\n### 1-2. Synchronization with Kernel Objects\n\n**Describes the sync wait functions and sync-only kernel objects provided by Windows**\n\n**Usefulness and utilization of threads or window messages**\n\n\u003cbr/\u003e\n\n-   **Thread Synchronization API**\n    -   Description of the standby function that waits for threads to synchronize\n    -   Understand the relationship between the standby function and the kernel object\n\n**_Thread Waiting Functions_**\n\n└─6. [WaitThread](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/06_WaitThread/WaitThread.cpp)\n\n└─7. [MyThread2](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/07_MyThread2/MyThread2.cpp)\n\n└─8. [WaitMultiThreads](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/08_WaitMultiThreads/WaitMultiThreads.cpp)\n\n\u003cbr/\u003e\n\n-   **Synchronization objects for data protection**\n    -   Describe Mutex and Semaphore from the perspective of protection of shared resources\n\n**_Mutex_**\n\n_Mutually exclusive access_\n\n└─9. [MutexTest](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/09_MutexTest/MutexTest.cpp)\n\n└─10. [MutexNoti](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/10_MutexNoti/MutexNoti.cpp)\n\n**_Semaphore_**\n\n_Mutexes provide exclusive access to a shared resource, while semaphores control access to a pool of resources._\n\n└─11. [SemaphoreTest](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/11_SemaphoreTest/SemaphoreTest.cpp)\n\n└─12. [TPSemaphore](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/12_TPSemaphore/TPSemaphore.cpp) : Thread Pool Using Semaphore\n\n└─13. [WQSemaphore](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/13_WQSemaphore/WQSemaphore.cpp) : Waitable Queue\n\n\u003cbr/\u003e\n\n-   **Synchronization object for flow control**\n    -   Description of synchronization-only objects for the purpose of controlling and notifying flows between threads.\n\n**_Event_**\n\n└─14. [ExitWithEvent](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/14_ExitWithEvent/ExitWithEvent.cpp)\n\n└─15. [MyThread3](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/15_MyThread3/MyThread3.cpp)\n\n└─16. [EventTest](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/16_EventTest/EventTest.cpp)\n\n└─17. [MultiSyncWaits](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/17_MultiSyncWaits/MultiSyncWaits.cpp)\n\n**_Using Events as Signaling Mechanisms_**\n\n└─18. [EventNotify](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/18_EventNotify/EventNotify.cpp)\n\n└─19. [WQNotify](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/19_WQNotify/WQNotify.cpp)\n\n└─20. [EventNotify2](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/20_EventNotify2/EventNotify2.cpp)\n\n**_Using Events for RW Lock_**\n\n└─21. [EvtRWLock](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/21_EvtRWLock/EvtRWLock.cpp)\n\n└─22. [EvtRWLock2](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/22_EvtRWLock2/EvtRWLock2.cpp)\n\n**_Waitable Timer_**\n\n└─23. [WaitableTimerTest](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/23_WaitableTimerTest/WaitableTimerTest.cpp)\n\n└─24. [WaitableTimerTest2](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/24_WaitableTimerTest2/WaitableTimerTest2.cpp)\n\n└─25. [ManualWTTest](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/25_ManualWTTest/ManualWTTest.cpp)\n\n└─26. [WakeSleepSystem](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/26_WakeSleepSystem/WakeSleepSystem.cpp)\n\n└─27. [SetWaitableTimerEx](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/27_SetWaitableTimerEx/SetWaitableTimerEx.cpp)\n\n\u003cbr/\u003e\n\n-   **Notification**\n    -   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.\n\n**_Integration of Thread and Message Queue_**\n\n└─28. [MsgNotify](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/28_MsgNotify/MsgNotify.cpp)\n\n└─29. [MsgQueue](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/29_MsgQueue/MsgQueue.cpp)\n\n└─30. [MsgWaitMulti](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/30_MsgWaitMulti/MsgWaitMulti.cpp)\n\n**_Combining with Callback Functions_**\n\n└─31. [WaitPool](https://github.com/gunh0/Windows_System_Programming/blob/master/WindowsSystemProgramming/31_WaitPool/WaitPool.cpp)\n\n**_.NET BackgroundWorker_**\n\n└─32. [BackgroundWorker](https://github.com/gunh0/windows-system-programming/tree/master/WindowsSystemProgramming/32_BackgroundWorkerr)\n\n\u003cbr/\u003e\n\n\u003cbr/\u003e\n\n---\n\n### 1-3. User Mode Synchronization\n\n**Windows provides various synchronization kernel objects that operate in kernel mode, as well as synchronization objects and APIs that operate in user mode.**\n\n**In user mode, a combination of spin lock and kernel-mode switching or a separate method is used for synchronization.**\n\n**Therefore, one of the advantages of user-mode synchronization is its speed.**\n\n**By minimizing the switch to kernel mode, thread context switching can also be reduced, making it faster than synchronization using kernel objects.**\n\n\u003cbr/\u003e\n\n-   **Critical Section**\n\n    -   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.\n\n    -   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.\n\n    -   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.\n\n    -   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.\n\n**_Using Critical Section_**\n\n└─33. [LockAccount](https://github.com/gunh0/Windows_System_Programming/tree/master/WinSysProg_Csharp/33_LockAccount)\n\n└─34. [CriticalSectionAccount](https://github.com/gunh0/windows-system-programming/tree/master/34_CriticalSectionAccount/CriticalSectionAccount.cpp)\n\n└─35. [CriticalSectionTest](https://github.com/gunh0/windows-system-programming/tree/master/35_CriticalSectionTest/CriticalSectionTest.cpp)\n\n└─36. [MyCSLock](https://github.com/gunh0/windows-system-programming/tree/master/36_MyCSLock/MyCSLock.cpp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgunh0%2Fwindows-system-programming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgunh0%2Fwindows-system-programming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgunh0%2Fwindows-system-programming/lists"}