Subject: While & Suspend()

From: [email-masked] (Loyd Blankenship)
Date: Tue, 31 Aug 1993 17:13:39 -0700

I've been told by a couple of people that it is bad practice to put a
suspend() inside a while loop. The claim was that the while loop was
continually checked even while the process was suspended.

Is this true? I've been ping-ponging verbs to avoid the practice, but would
just as soon not have to.

Loyd

***************************************************************************
* [email-masked]	     SJ Games: 1	     *	Loyd Blankenship  *
* GEnie: SJGAMES	     US Secret Service: 0    *	PO Box 18957	  *
* Compu$erve: [73407,515]			     *	Austin, TX 78760  *
* cs.utexas.edu!dogface!fnordbox!loydb		     *	512/447-7866	  *
***************************************************************************

---

From: Pavel Curtis <[email-masked]>
Date: Wed, 1 Sep 1993 18:06:21 -0700

> Date:	Tue, 31 Aug 1993 17:13:39 -0700
> From:	[email-masked] (Loyd Blankenship)
> 

This is nonsense; while your task is suspended, it isn't doing anything at all
or using up any noticeable amount of server resources.

You probably don't want to suspend every time through the loop, though, since
that would slow your task down considerably; rather, you should probably use
something like $command_utils:suspend_if_needed(), which checks whether or not
you're close to running out of ticks or seconds.

	Pavel

---

From: Roger Crew <[email-masked]>
Date: Wed, 1 Sep 1993 18:44:58 -0700

>   continually checked even while the process was suspended.

not true.

There *is* a rather common novice-programmer mistake with FORK in
which someone will write something like

  WHILE (<test>)
    <stuff>
    FORK (n)
      <more-stuff>
    ENDFORK
  ENDWHILE

when s/he really wanted to do something like

  WHILE (<test>)
    <stuff>
    suspend(n);
    <more-stuff>
  ENDWHILE

The former spins off a new forked task each time through the loop and
moreover all of these tasks appear *immediately* in the task queue
(assuming <stuff> contains no suspends), thus spamming the player into
next Tuesday.

The key point is that executing a fork is essentially a no-op as far 
as the parent task is concerned.

My guess is that somebody was trying to warn you about this and got 
FORK confused with suspend.

Not that there aren't legitimate reasons to put a fork inside a
loop---consider the following version of :announce

  FOR p IN (setremove(this.contents,player))
    FORK (0)
      p:tell(msg);
    ENDFORK
  ENDFOR

which guards against broken :tell verbs by putting each :tell in its
own task---but it's generally *very* expensive; you incur the overhead
of creating a new task for EACH iteration of the loop.

--
Roger Crew
Internet:   [email-masked]
LambdaMOO:  Rog