[fpc-pascal] Counting semaphore for free pascal

Michael Schnell mschnell at lumino.de
Wed Jul 29 13:46:30 CEST 2015


On 07/29/2015 01:10 PM, kapibara wrote:
>
> In an application you have N number of threads and they all want to 
> access a service. Now, for example, only five threads are allowed to 
> have access at the same time. ..

I suppose that easily can be made by two critical sections.

One is used to protect the mutual access to the counter variable (here 
you could use an atomic operation - provided in the FPC library - as 
well, this might provide better performance, but does nit seem necessary 
for that purpose here.

The second is used to provide the actual waiting and is only entered if 
the count is over the top.

-Michael




More information about the fpc-pascal mailing list