Am 28.07.2015 20:14 schrieb "kapibara" <kapibara....@aol.com>:
>
> Hi there,
>
> A counting, or general, semaphore limits simultaneous access to a
resource according to the number of permits you specify. On the other hand,
a binary semaphore like a critical section limits the access to "one at a
time".
>
> FPC doesn't seem to have a general semaphore? I recently attempted to
implement one, here is the code, plus a working Lazarus demo attached. It
blocks on an event instead of a critical section. However, I didnt manage
to have it block by just calling Wait, because then the code blocked
without leaving the PermitLock and that meant deadlock for all threads. So
thats why you see the "if Semaphore.Wait(aEvent) then
RTLEventWaitFor(aEvent)" instead of just Semaphore.Wait(aEvent). It works
just fine, but if anyone knows how to implement this by just calling
Wait(aEvent), please tell. If you want to block on a critical section
instead of an event, do that. Perhaps the result could be TFPSemaphore and
go with FPC.

Any TSemaphore implementation should provide the same methods that Delphi's
TSemaphore provides:
http://docwiki.embarcadero.com/Libraries/XE6/en/System.SyncObjs.TSemaphore

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to