You wonβt learn much if someone else does your work for you, but here is the semaphore implementation in user mode that I wrote:
https://github.com/vinniefalco/VFLib/blob/master/modules/vf_core/threads/vf_Semaphore.h https://github.com/vinniefalco/VFLib/blob/master/modules/vf_core/threads/vf_Semaphore.cpp
Of course, you will need to map WaitableEvent, SpinLock, and Atomic to their respective counterparts based on your environment (conditional variable, mutex, and atomic integer operation, respectively). You also need to provide a simple stack, or you can adapt the locking implementation from my library. Please note that if you decide to go without blocking, you will have to keep the βdeleted listβ hanging or you will get an ABA problem.
source share