TheDude
TheDude

Reputation: 3105

How to empty OmniThreadLibrary ThreadPool Queue?

I just discovered OmniThreadLibrary & started playing with it. I'm trying to launch, say, no more than 20 tasks max and send the rest of the tasks to queue.

I modified the OmniThreadLibrary's 00_Beep project to do this:

const
  TASKS_COUNT = 100;

procedure TfrmTestSimple.btnBeepClick(Sender: TObject);
var
    I: Integer;
begin
    with OmniEventMonitor do
        for I := 1 to TASKS_COUNT do
            Monitor(CreateTask(Beep, 'Beep-' + IntToStr(I))).Schedule;
end;

procedure TfrmTestSimple.FormCreate(Sender: TObject);
begin
    GlobalOmniThreadPool.MonitorWith(OmniEventMonitor);
    GlobalOmniThreadPool.MaxExecuting := 20;
    GlobalOmniThreadPool.MaxQueued := 0;
end;

It works but if I increase the # of tasks (ie. TASKS_COUNT) to, say, 7000, I get an exception:

TOmniCommunicationEndpoint.Send: Queue is full

I read whatever I could find (OTL blog and forums, sample projects, googled a lot, etc...), it seems that to prevent this, I must empty the queue periodically.

So I tried this but it didn't work:

procedure TfrmTestSimple.OmniEventMonitorTaskTerminated(const task: IOmniTaskControl);
begin
    Task.Terminate(1);       // I also tried: Task.Terminate(0);
    Task.Comm.Reader.Empty;  // Task.Comm.OtherEndpoint.Reader.Empty; didn't work either
    Task.Comm.Writer.Empty;  // Task.Comm.OtherEndpoint.Writer.Empty; didn't work either
end;

Any advice on how to empty the queue and avoid this exception?

I know that some may say that such a large number of tasks in queue is ridiculous, suffice to say it's neither a hypothetical question nor it's in the scope of my question to tell me to redesign my application, at this point I just need to know the limit of the queuing system in OTL and how to bypass this limitation.

Thanks in advance!

Upvotes: 2

Views: 1301

Answers (1)

TheDude
TheDude

Reputation: 3105

Well, this form post doesn't show how to empty OmniThreadLibrary ThreadPool queue, but it does show how to make a virtually unlimited waiting queue for OmniThreadLibrary (which is basically my goal):

http://otl.17slon.com/forum/index.php/topic,354.0.html

Thanks for all the help that I've received here, you guys are awesome!

Upvotes: 2

Related Questions