Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-09

Multi-Threading and usage of Semaphors under FPC

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

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 -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/
Jonas Maebe
to Graeme Geldenhuys
Graeme Geldenhuys wrote 6 lines
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?

Using the thread manager directly is not supported. There is no counting semaphore abstraction available in FPC at this point, as far as I know.

Jonas