Figure 1: Pseudo-Code for CPrioritySemaphore::Wait

CPrioritySemaphore::Wait(LONG lPriority)
{

   enter the critical section
   if( lPriority is not the lowest priority level )
   {
      increment the thread count for level lPriority
      reset the event associated with level lPriority
   }
   leave the critical section
  
   wait for the semaphore and all events associated with 
   levels X, where X > lPriority, to be simultaneously signalled
  
   enter the critical section
   if( lPriority is not the lowest priority level )
   {
      decrement the thread count for lPriority
      if( the thread count for level lPriority equals 0 )
      {
         set the event associated with level lPriority
      }
   }
   leave the critical section

}