Hi,
I had a previous discussion about Semaphores. Apparently my usage of them was not very good, because they were specific to the Linux system and Posix. Anyway, I was told it is better to use the ThreadManager.
So how do I translate code as show below to using the FPC ThreadManager? I can see where I can set specific information for the FPC Threadmanager -> Semaphore compared to the code below...
-----------------------
procedure TtiPool.CreatePoolSemaphore;
begin
{$IFDEF MSWINDOWS}
if FSemaphore 0 then
CloseHandle(FSemaphore);
FSemaphore := CreateSemaphore(nil, FMaxPoolSize, FMaxPoolSize, nil);
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
sem_destroy(FSemaphore);
if sem_init(FSemaphore, 0, FMaxPoolSize) 0 then
raise Exception.Create('Failed to create the semaphore');
{$ENDIF UNIX}
end;
-----------------------This is what I tried, but like I said, how to I set the min and max poolsize etc?
var
FThreadMgr: TThreadManager;
p: pointer;
....
if not GetThreadManager(FThreadMgr) then
raise Exception.Create('Failed to reach the FPC thread manager');
p := FThreadMgr.SemaphoreInit;See the problem? SemaphoreInit doesn't take parameters. What am I missing here? Sorry if this all sounds dumb, but I am not well versed when it comes the multi-threaded programming.
Regards,
- Graeme -
