title: Too many Post were made to semaphore
body: <p>Hi have developped an sample code to implement.Multiple producer and single consumer problem. </p>
  
  <p>I have taken a Queue and I have restricted the size of the to 20.So I am using semaphore  and CrticalSection (windows api)to protect it.If more than 20 thread the queue it wont be allowed.that semaphore should protect it.</p>
  
  <p>I have two method AdddTail(add msg in queue) and Remove Head (remove msg from the queue)method to manipulate the queue.</p>
  
  <p>I am getting Error <strong>Too many Post were made to semaphore</strong>.I dont understand the problem.
  I have 20 Producer thread with 8000 ms waiting and one consumer thread with 4000 ms wating.
  I think ReleaseSemaphore is Causing the Problem.</p>
  
  <pre><code>BOOL CEventQueue::AddTail(LPVOID p)
  { 
  
         BOOL result;
         char* pMsg = (char*)p;
         char* pMsg1 = new char[100];
         int nOffset = strlen(pMsg);
  
         strcpy(pMsg1,pMsg);
         strcat(pMsg1," Waiting");
         PostMessage(hWnd,UWM_ONUPDATEPRODUCERLIST,(WPARAM)pMsg1,0);
         DWORD dwWaitResult = WaitForSingleObject(handles,INFINITE);
         switch(WAIT_OBJECT_0)
         {
         case WAIT_OBJECT_0:
             {
             ::EnterCriticalSection(&amp;m_QueueLock);
             queue.AddTail(p);
              ::LeaveCriticalSection(&amp;m_QueueLock);
             result = ::ReleaseSemaphore(handles[SemaphoreIndex],1, NULL);
             }
             break;
         case WAIT_TIMEOUT:   
             return 0;
             break;
         }      
         if(!result)
         { /* failed */
             // caller can use ::GetLastError to determine what went wrong
             queue.RemoveTail();
            ErrorExit(_T("AddTail"));
         } /* failed */
  
         return result;
  } // AddTail
  
   LPVOID result;
  
         switch(::WaitForMultipleObjects(2, handles, FALSE, INFINITE))
         {
              /* decode */
              case StopperIndex:   // shut down thread
                ::ExitThread(0);  // kill thread
                return NULL;      // return keeps C compiler happy
  
              case SemaphoreIndex: // semaphore
                ::EnterCriticalSection(&amp;m_QueueLock);
                result = queue.RemoveHead();
                ::LeaveCriticalSection(&amp;m_QueueLock);
                return result;
  
              case WAIT_TIMEOUT: // not implemented
              default:
              ASSERT(FALSE); // impossible condition
              return NULL;
              //::ReleaseSemaphore(handles[SemaphoreIndex],1, NULL);
        } /* decode */
  </code></pre>