comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: How to determine if task is busy or not?
Date: Sat, 8 Aug 2009 07:59:51 -0700 (PDT)
Date: 2009-08-08T07:59:51-07:00	[thread overview]
Message-ID: <4aef99b6-6ac6-4e0b-91d8-2a5320ea6e9c@l34g2000vba.googlegroups.com> (raw)
In-Reply-To: f3vn6yuhml4u$.10sxy6foyizyf.dlg@40tude.net

On 8 Sie, 13:27, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:

> The scheme described by Ludovic is not only simpler, it is also race
> condition free. The reverse scheme has a race condition in it. If you have
> asked if a task is idle, you do not know if it still is right now

Depends. If it is the asking entity that is also providing the job,
then the problem above cannot happen. In other words, if the "manager"
asks the task whether it is busy or idle and the answer is "idle",
then that answer it true until the same manager provides new work
unit, because there is no other way for the task to switch from "idle"
to "busy". Which means that the manager can always safely handle a new
work unit to the "idle" task, no race is possible.

The race can happen the other way round, though: the manager asks the
task for its status, the task answers "busy" and the manager takes
some decision based on this answer (move on to another task, perhaps?)
even though it might not be true anymore (the task in question might
be already "idle" by that time). This kind of race might be
acceptable, though, at most at the price of underutilized on
unbalanced server.

The advantage of such a setup is that the manager knows whether the
work can be handled *immediately* by any one of the tasks in the pool.
False negatives can be harmless, as long as the positives are
accurate.

Using a queue, as suggested by Ludovic, makes sense only when the work
units can *wait* for being processed. This might or might not be the
case.

There are examples of systems where either of these schemes are good
(batch processing vs. real-time?). I would not say that one is better
than another.

To Tomek - the simplest way to deploy your original idea is to use a
flag (Busy/Idle - an enumeration type is perfect here), which is
shared and used by both the worker task and its manager. Protected
object is a proper solution here and you might even use the same
protected object for managing both the flag and the work unit itself.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



  reply	other threads:[~2009-08-08 14:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-08 10:49 How to determine if task is busy or not? Tomek Walkuski
2009-08-08 10:56 ` Ludovic Brenta
2009-08-08 11:27   ` Dmitry A. Kazakov
2009-08-08 14:59     ` Maciej Sobczak [this message]
2009-08-08 16:00       ` Tomek Wałkuski
2009-08-08 18:22       ` Dmitry A. Kazakov
2009-08-08 18:39         ` Ludovic Brenta
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox