[fpc-pascal] Semaphore
Jonas Maebe
jonas.maebe at elis.ugent.be
Tue Feb 12 14:44:08 CET 2008
On 12 Feb 2008, at 14:20, Damien Gerard wrote:
> Le Feb 12, 2008 à 12:36 PM, Graeme Geldenhuys a écrit :
>
>> 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;
>>
>
> Thanks !
>
> I think I can safely change LINUX by UNIX and it should work on OS X
> too.
No, you can't, because sem_init does not exist on Mac OS X. Use the
RTL implementation, it works on all platforms. Further, the above code
looks buggy because it always calls sem_destroy for FSemaphore, even
it was not allocated (and that may cause the program to crash,
depending on the contents of FSemaphore at that point and the
implementation of sem_init).
Jonas
More information about the fpc-pascal
mailing list