[fpc-pascal] Semaphore

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Feb 12 12:36:30 CET 2008


On 11/02/2008, Damien Gerard <milipili at shikami.org> wrote:
> My program must work under OSX/Nux and Windows.
> I may have missed something but I can not find something suitable for
> me.
> Under Windows OpenSemaphore, under unixes CurrentTM.Semaphore*...
>
> Is there any TSemaphore class of equivalent ? Or may be an example how
> to use Semaphores ? :)

I've wondered the same thing.... In the end I had to write code like
the following:
Not idea, but it works. We needed to support Linux and Windows only.


procedure TtiPool.CreatePoolSemaphore;
begin
  {$IFDEF MSWINDOWS}
  if FSemaphore <> 0 then
    CloseHandle(FSemaphore);
  FSemaphore := CreateSemaphore(nil, FMaxPoolSize, FMaxPoolSize, nil);
  {$ENDIF MSWINDOWS}
  {$IFDEF LINUX}
  sem_destroy(FSemaphore);
  if sem_init(FSemaphore, 0, FMaxPoolSize) <> 0 then
    raise Exception.Create('Failed to create the semaphore');
  {$ENDIF LINUX}
end;



Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list