Recent

Author Topic: Threaded TProcess?  (Read 2550 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Threaded TProcess?
« on: August 05, 2021, 07:54:21 pm »
A quick question: Is there somewhere a variant of TProcess but running on its own thread (kind of TThreadedProcess)? Or do I have to BMO?

Yeah, I know it's an easy task but if I can avoid doing it ... 8-)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 2667
Re: Threaded TProcess?
« Reply #1 on: August 05, 2021, 09:45:30 pm »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Threaded TProcess?
« Reply #2 on: August 05, 2021, 10:35:55 pm »
Thanks Winni, interesting reading but ... I already have that forum thread saved to my "info" folder and I do know how to build what I want, up to making a component with it ;)
(Yah, I know: "famous last words" :D)

I only wanted to know if there was something like that ready-made so as to don't waste time doing it myself. Pure laziness, more than anything else ;D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9536
  • FPC developer.
Re: Threaded TProcess?
« Reply #3 on: August 05, 2021, 10:48:03 pm »
The problem is that you have at least two potentially blocking operations, read (from stdout/stderr) and write  (to stdin of the process). So will one thread be enough ? If one blocks a really long time the other will be starved.

As fedkad correctly remarked in the this morning's thread there is no easy solution to the write problem, but the read problem is abstracted by checking if it would block before reading (e.g. in runcommandloop)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Threaded TProcess?
« Reply #4 on: August 06, 2021, 12:16:52 am »
Yeah, I've been following that thread with full attention precisely because I am in the planning stages of my component. I think it can be done with just one thread but that's just a "feeling" yet.

Anyway, for the first use it is being designed we'll not be needing reading/writing from the process pipes so we can go ahead with a minimalist design. Heck, we could probably even just call RunCommand() in the thread and ignore outputstring though
we are (or rather I am) going to use a full TProcess so that we can terminate or kill it at will if the need arise, etc. I.e. because I like having full control (or as much as possible) of external things, in case they go haywire.

And, of course, because if you set out to make a thing like this you may as well do it right :D

Though I would much prefer spending the weekend otherwise, TBH. Thence this thread ;D
« Last Edit: August 06, 2021, 12:20:58 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018