Once you have obtained the semaphore and completed any operations on the semaphore protected object, you should release the semaphore. The releasesemaphore() function does this. for each successful obtainsemaphore(), obtainsemaphoreshared() and attemptsemaphore() call you make, you must have a matching ReleaseSemaphore() call.