I'm creating a semaphore in my program's main window. The semaphore is created like this:
if(!(d.hSemf= CreateSemaphore(0, THREAD_COUNT, THREAD_COUNT, 0)))
In each thread that is created, i WaitForSingleObject(d->hSemf, INFINITE) to signal that it still is running.
When the thread is closing, i ReleaseSemaphore(d->hSemf, 1, 0) to signal that it is closed.
In the main window's WM_DESTROY, i try to wait for the threads to close by using the following code:
This doesn't work, and i can't figure out why!?
if((lRes=WaitForSingleObject(d.hSemf, 100))!=WAIT_OBJECT_0 && lRes!=WAIT_TIMEOUT)