1

By re-initialize, I mean stop the running tasks (or even kill the threads if I have to) & revert back as if the pipeline/threads were never initialized / started.

My code (I'm using delphi 2010, OmniThreadLibrary 3.02) looks like this:

procedure SomeProc();
var
   AFile : TOmniValue;
begin
     APipeline := Parallel.Pipeline.NumTasks(5).Stage(StageProc).Run;

     AFile.CreateNamed(['FileID', FileID, 'FileName', FileName]);
     MyPipeline.Input.Add(AFile);
end;
// --------------- //
procedure StageProc(const Input, Output : IOmniBlockingCollection; const Task : IOmniTask);
begin
    // ...
end;

I need something like this:

// --------------- //
procedure ResetPipeline();
begin
     // Stop any task running inside StageProc() & reset pipeline, ie.
     KillTasks(pipeline);
     pipeline := nil;
end;

Notes

  1. FWIW, yes, I'm fully aware that this is really a bad idea!

  2. I'm also well aware that the best approach would be to send a stop signal to tasks and wait for them to nicely shutdown, and check often for stop signals inside tasks. I'm not interested in that for this very particular case.

  3. Although the code above only mention pipelines, a solution to reset BackgroundWorker would be enough for me.

Thanks in advance!

TheDude
  • 3,045
  • 4
  • 46
  • 95
  • Send a stop signal. Like nature intended. I'd expect that OTL won't offer up routines for perform the sort of abuse that you are proposing. – David Heffernan Nov 10 '12 at 19:51
  • Thanks David, but as I *already* stated that I'm not interested in that in this particular case. I'm more interested in killing (or re-initializing the pipeline) rather than nicely stopping the tasks! (yes **even** given the downfalls of such approach) – TheDude Nov 10 '12 at 19:53

1 Answers1

0

Disclaimer: Forceful termination of threads is not advisable – please don't try this at home.

I believe you can do what you want like this:

GlobalParallelPool.WaitOnTerminate_sec := 0;
GlobalParallelPool.CancelAll;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thanks David but I'm afraid that **didn't terminate neither tasks nor threads**. Again, I **really** understand how bad it is to terminate threads but in my *particular case*, it's both safe and the way to go.. – TheDude Nov 11 '12 at 01:49
  • According to my reading of the code, this should result in a bunch of calls to TerminateThread. You have the code too, and a working test bed. Perhaps you could inspect in the debugger and work out why those TerminateThread calls don't run. – David Heffernan Nov 11 '12 at 08:47
  • I did; it lead me to nowhere (plus I'm not comfortable changing OTL, I don't want to break something). Primoz (OTL author) [aknowledged here](http://otl.17slon.com/forum/index.php/topic,426.msg1488.html#msg1488) that there are indeed valid reasons to kill a **task** (although I'm pretty sure it *will* be abused) – TheDude Nov 12 '12 at 16:58
  • FWIW, I finally resolved in my particular case to literally **kill the EXE** (it's an invisible EXE running in the background), it's really a shame that I have to resolve to such brutal techniques, but until OTL allows this, it seems there's no way to reset/kill tasks in OTL. – TheDude Nov 12 '12 at 17:00