< span class = "rem" > // Define the semaphore to control 3 permits. </span>

< span class = "rem" > // 3 Threads can acquire the <span class="GINGER_SOFATWARE_noSuggestion GINGER_SOFATWARE_correct">mySemaphore</span> </span>

Semaphore < span class = "GINGER_SOFATWARE_noSuggestion GINGER_SOFATWARE_correct" > mySemaphore < / span > = < span class = "kwrd" > new < / span > Semaphore < span class = "GINGER_SOFATWARE_correct" > ( < / span > 3 , < span class = "kwrd" > true < / span > ) ;

< span class = "rem" > // 3 threads can execute this line of code. The 4 thread must wait for a release</span>

< span class = "GINGER_SOFATWARE_correct" > mySemaphore < / span > < span class = "GINGER_SOFATWARE_correct" > . < / span > acquire < span class = "GINGER_SOFATWARE_correct" > ( < / span > ) ;

< span class = "rem" > // .. <span class="GINGER_SOFATWARE_correct">somewhere</span> in the <span class="GINGER_SOFATWARE_correct">code a thread</span> releases the <span class="GINGER_SOFATWARE_noSuggestion GINGER_SOFATWARE_correct">mySemaphore</span>, </span>

< span class = "rem" > // <span class="GINGER_SOFATWARE_correct">and</span> now the next waiting thread can acquire</span>