[fpc-pascal] semaphores?

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Apr 14 09:06:14 CEST 2009


On Mon, Apr 13, 2009 at 11:49 PM, Seth Grover <sethdgrover at gmail.com> wrote:
> Is there not a cross-platform semaphore API in Free Pascal? I planned

About 4 years ago there wasn't, so I had to use IFDEF's in my code. I
haven't looked in newer versions of FPC if there is a cross-platform
API available. I would be interested in this as well.

This is what I had to do...

[...snip...]
    {$IFDEF MSWINDOWS}
    FSemaphore : THandle;
    {$ENDIF MSWINDOWS}
    {$IFDEF LINUX}
    FSemaphore : TSemaphore;
    {$ENDIF LINUX}
[...snip...]


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