[fpc-pascal] Re: Semaphore problems

Marco van de Voort marcov at stack.nl
Mon Jul 24 15:36:25 CEST 2006


> Looking at my code, I might have initialized my semaphore incorrectly.
> 
> The Windows portion works, and I tried to port it to Linux as follows...
> 
> procedure TtiPool.CreatePoolSemaphore;
> begin
>   {$IFDEF MSWINDOWS}
>   if FSemaphore <> 0 then
>     CloseHandle( FSemaphore ) ;
>   FSemaphore := CreateSemaphore( nil, FiMaxPoolSize, FiMaxPoolSize, nil );
>   {$ENDIF MSWINDOWS}
>   {$IFDEF LINUX}
>   sem_destroy( FSemaphore );
> 
>   if sem_init(FSemaphore, 0, 1) <> 0 then
>     raise Exception.Create('Failed to create the semaphore');
>   {$ENDIF LINUX}
> end;

Looking at unit syncobjs might save you some ifdefs and trouble.




More information about the fpc-pascal mailing list