I am trying to create a simple semaphore that will allow only 1 thread to increment a count variable but what I am currently doing does not seem to work. Is there something wrong with my syntax or am I completely on the wrong track? (I named the semaphore mutex, because it can only have a value of 0 or 1)
WaitForSingleObject(mutex, 0);
count = count + 1;
ReleaseSemaphore(mutex, 1, NULL);
From the MSDN page, with emphasis added: