Threads
Native Processes and Threads is a deep subject that’s well-documented on the Microsoft site. Knock yourself out. The workhorse functions are below in the references.
Win32 provides several atomic functions through the Interlocked API, the highlights of which are InterlockedIncrement and InterlockedDecrement.
There are several Synchronization Objects - ’events’, mutexes, critical sections, semaphores, and waitable timers. Of these, events seem to crop up the most often. A critical section is like a mutex but scoped to a single process.
Use a counting semaphore to implement throttling, one use case would be to limit the number of concurrent network requests. The other synchronization objects all have a capacity of one.
Win32 also has Fibers. This is a niche API for specific use cases.
References
- CreateThread function (processthreadsapi.h) - Win32 apps | Microsoft Learn
- SuspendThread function (processthreadsapi.h) - Win32 apps | Microsoft Learn
- ResumeThread function (processthreadsapi.h) - Win32 apps | Microsoft Learn
- ExitThread function (processthreadsapi.h) - Win32 apps | Microsoft Learn
- GetExitCodeThread function (processthreadsapi.h) - Win32 apps | Microsoft Learn
- CloseHandle function (handleapi.h) - Win32 apps | Microsoft Learn
- GetCurrentThreadId function (processthreadsapi.h) - Win32 apps | Microsoft Learn
- Sleep function (synchapi.h) - Win32 apps | Microsoft Learn
- Interlocked Variable Access - Win32 apps | Microsoft Learn
- InterlockedIncrement function (winnt.h) - Win32 apps | Microsoft Learn
- InterlockedDecrement function (winnt.h) - Win32 apps | Microsoft Learn
- Synchronization Objects - Win32 apps | Microsoft Learn
- SetEvent function (synchapi.h) - Win32 apps | Microsoft Learn
- ResetEvent function (synchapi.h) - Win32 apps | Microsoft Learn
- WaitForSingleObject function (synchapi.h) - Win32 apps | Microsoft Learn
- WaitForMultipleObjects function (synchapi.h) - Win32 apps | Microsoft Learn