[fpc-pascal] Semaphore

Damien Gerard milipili at shikami.org
Tue Feb 12 14:54:09 CET 2008


Le Feb 12, 2008 à 2:44 PM, Jonas Maebe a écrit :

>
> 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).
>

sem_* don't came from pthreads ?
Under OS X you can do
{$ifdef unix}
uses
  cthreads;
{$endif}

I thought it would follow the same behavior. But I agree RTL is my  
friend :)

>
> Jonas_______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



--
Damien Gerard
milipili at shikami.org

Le temps n'a pas d'importance. Seul le code est important
    -- (f00ty)







More information about the fpc-pascal mailing list