[Lazarus] Using semaphores to limit thread access

Sven Barth pascaldragon at googlemail.com
Sun Jul 19 22:33:29 CEST 2015


Am 19.07.2015 18:33 schrieb "kapibara" <kapibara.pas at aol.com>:
>
> Hi guys
>
> A number of threads need to access an object, but no more than three
threads must access simultaneously.
>
> Thats a job for a semaphore someone said. I understand that under Delphi
and Windows something like this could be used:
>
> FSemaphoreHandle := CreateSemaphore(nil, 3, 3, nil);
> WaitForSingleObject(FSemaphoreHandle, <timeout>);
>
> How to do that under Lazarus and Linux?
>
> I have found TThreadManager with its SemaphoreInit and SemaphoreWait etc.
But how to use it, especially how do you specify the number of threads that
can access the object?
>
> Using 32 bit Lazarus trunk and FPC trunk.

FPC does not yet have a public semaphore API. The functions in
TThreadManager are only implemented on Unix systems ans only used for
specific purposes inside the RTL.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20150719/1ee455cf/attachment-0003.html>


More information about the Lazarus mailing list