Recent

Author Topic: Thread pool in Lazarus ?  (Read 7491 times)

zotak

  • Newbie
  • Posts: 1
Thread pool in Lazarus ?
« on: July 15, 2015, 10:23:37 am »
There is such thing in Lazarus?
I'm starting few threads from different forms and I want to limit the global number of simultaneous threads to 3 (my processor has 4 cores).I need something like a thread pool that will queue the new  started threads so that only 3 simultaneous threads can run in parallel.

Thank you!

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Thread pool in Lazarus ?
« Reply #1 on: July 15, 2015, 12:37:08 pm »
Yes, and pretty simple to use. http://wiki.freepascal.org/Parallel_procedures
Lazarus 1.7 (SVN) FPC 3.0.0

Graeme

  • Hero Member
  • *****
  • Posts: 1434
    • Graeme on the web
Re: Thread pool in Lazarus ?
« Reply #2 on: July 15, 2015, 04:47:50 pm »
I don't think Lazarus includes something like that as standard, but there are plenty of existing implementations you can use. eg: The tiOPF project http://www.tiopf.com includes a very well unit tested thread pool in the <tiopf>/Core/tiThreads.pas unit.

http://sourceforge.net/p/tiopf/code/ci/tiopf2/tree/Core/tiThread.pas
http://sourceforge.net/p/tiopf/code/ci/tiopf2/tree/Core/tiPool.pas
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

kapibara

  • Hero Member
  • *****
  • Posts: 654
Re: Thread pool in Lazarus ?
« Reply #3 on: July 15, 2015, 06:22:09 pm »
Maciej Kaczkowski's MapViewer also contains a threadpool:

https://code.google.com/p/mapviewer/source/browse/


Lazarus trunk / fpc 3.2.2 / Kubuntu 24.04 - 64 bit

JD

  • Hero Member
  • *****
  • Posts: 1909
Re: Thread pool in Lazarus ?
« Reply #4 on: July 16, 2015, 05:24:47 pm »
@zotak
You can also use Pooling Objects for Delphi found at https://code.google.com/p/delphipooling/.

It works in Lazarus. I've used it in client-server applications to create a database connection pool on the server side AND a thread pool for querying and data retrieval on the client side. I like it because you can limit the size of the pool or allow it to grow dynamically if the need arises.

@Graeme
I unfortunately did not do a thorough appraisal of tiOPF before I wrote my data applications.  :( I would not have had to reinvent the wheel so often. I took a look at tiOPF2 & it would have helped me get up to speed faster if I had used it. When will tiOPF3 be ready?

JD
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

 

TinyPortal © 2005-2018