<p>Am 28.07.2015 20:14 schrieb "kapibara" <<a href="mailto:kapibara.pas@aol.com">kapibara.pas@aol.com</a>>:<br>
><br>
> Hi there,<br>
><br>
> 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".<br>
><br>
> 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.</p>
<p>Any TSemaphore implementation should provide the same methods that Delphi's TSemaphore provides: <a href="http://docwiki.embarcadero.com/Libraries/XE6/en/System.SyncObjs.TSemaphore">http://docwiki.embarcadero.com/Libraries/XE6/en/System.SyncObjs.TSemaphore</a></p>
<p>Regards,<br>
Sven</p>