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@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



--
Damien Gerard
[EMAIL PROTECTED]

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




_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to