[fpc-pascal] Counting semaphore for free pascal

Serguei TARASSOV serge at arbinada.com
Thu Jul 30 19:23:17 CEST 2015


On 30/07/2015 12:00, fpc-pascal-request at lists.freepascal.org wrote:
> Date: Wed, 29 Jul 2015 17:05:03 +0200
> From: Michael Schnell<mschnell at lumino.de>
> To:fpc-pascal at lists.freepascal.org
> Subject: Re: [fpc-pascal] Counting semaphore for free pascal
> Message-ID:<55B8EB9F.6060202 at lumino.de>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 07/29/2015 04:47 PM, Serguei TARASSOV wrote:
>> >
>> >I see you're using two concepts of synchronization (semaphore and
>> >events) at the same time.
>> >Maybe better to separate them?
>> >It is not clear why use events to limit thread access to service.
> There are several implementation details a semaphore can have
>    - counting / not counting
What is "not counting semaphore"? Even a binary semaphore counts up to 1.
>    - if taken by a precess/thread will the same process/thread
> block/count when it tries a second take ?
Yes, re-entrant / non re-entrant
>    - if taken by a precess/thread is  a different process/thread allowed
> to free it ?
AFAIK, it is a mutex that have notion of ownership but a semaphore is 
not safe for such case.
>    - ...
>
Yes, there are multiple details depending on used scenarios that makes a 
generic implementation complex and hard to use.
So my question was to clarify the goals of the posted code.
I.e. a sleeping lock semaphore is expensive and is not appropriate in 
case of many short requests that is typically for multithreading 
applications.
However, I could share some simple semaphore implementation for 
non-sleeping and non-reentrant scenario.

Regards,
Serguei



More information about the fpc-pascal mailing list