Subject: How to make something turn on only once?

From: [email-masked]
Date: Sat, 19 Jun 1993 22:55:01 -0700

X-Operating System: SMP DC/OSx 1.0-92b011 dcosx
X-Mailer: ELM [version 2.3 PL11]

I want to make an object in LambdaMOO that one can turn on, after which
it does things for a while and then shuts off. The problem I have is 
keeping it from having more than one task going at once (if more
than one person turns it on).

I could put a gate in the object - test and set it when starting, and
clearing it when finishing. The problem is what if the task terminates
for some other reason (such as someone starts my gadget, then does aan
@kill_all). In that case, the gate will never be cleared.

I thought of putting the task_id of the first task to start it in the
object, but that has the same sort of problem. A subsequent task cannot
check to see if the first task is still running unless the first task
was fired off my the same player (if I'm reading the Programming
Manual right).

Has anyone solved this? Is there a generic I can look at?

[PS, my Reply-To is fixed on this message, unlike some of the ones from
last week which sent replies to [email-masked] - sigh]
-- 
John Moore     HAM:NJ7E    CAP:Thunderbird 381 
[email-masked] 
Voice: day or eve:(602) 951-9326 FAX:602-861-7642 (by prior arrangement)
USnail: 7525 Clearwater Pkwy, Scottsdale, AZ 85253 
Opinion: Support ALL of the bill of rights, INCLUDING the 2nd amendment!
Bad Advice: Long palladium, short petroleum ;-)

---

From: [email-masked] (Erik Ostrom)
Date: Sun, 20 Jun 1993 05:35:00 -0700

Unless the verb is wizardly and does a set_task_perms(), the task will be
owned by you, the owner of the verb that does the suspend() (or fork, or
$command_utils:suspend_if_needed()).  This will prevent other players from
killing the task, and also allows you to check if the first task is running.

---

From: Judy Anderson <[email-masked]>
Date: Mon, 21 Jun 1993 09:36:34 -0700

From: [email-masked]

$code_utils:task_valid(taskid).  It set_task_perms to $no_one and
tries killing the task, to see if it gets E_INVARG or E_PERM.  Pretty
recent; you'll probably have to copy it to your current MOO.

---

From: John Lamping <[email-masked]>
Date: Mon, 21 Jun 1993 09:45:39 -0700

I ran into this problem with Mr. Clean on LambdaMOO.  Specifically, the
gate would be set saying that there was a task running Mr. Clean and then
task running Mr. Clean would invoke a verb on some other object which would
bomb, blowing away Mr. Clean's task and leaving the gate set.

My solution was to put a time-limit on the gate.  At the time you set the
gate, you also record at what time in the future you expect to be finished.
If the task running the object discovers it needs more time, it is free to
increase this estimate.  When someone checks the gate, they also compare
the current time to the time limit, and if the current time is beyond the
limit, the task running the object is presumed dead and the gate is treated
as if it were not set.