/
html/
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from ProgrammersManual.texinfo on 4 March 1997 -->

<TITLE>LambdaMOO Programmer's Manual - Tasks</TITLE>
</HEAD>
<BODY>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_37.html">previous</A>, <A HREF="ProgrammersManual_39.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>.
<P><HR><P>


<H2><A NAME="SEC38" HREF="ProgrammersManual_toc.html#TOC38">MOO Tasks</A></H2>

<P>
A <STRONG>task</STRONG> is an execution of a MOO program.  There are five kinds of tasks
in LambdaMOO:

</P>

<UL>
<LI>

Every time a player types a command, a task is created to execute that
command; we call these <STRONG>command tasks</STRONG>.
<LI>

Whenever a player connects or disconnects from the MOO, the server starts a
task to do whatever processing is necessary, such as printing out
<SAMP>`Munchkin has connected'</SAMP> to all of the players in the same room; these
are called <STRONG>server tasks</STRONG>.
<LI>

The <SAMP>`fork'</SAMP> statement in the programming language creates a task whose
execution is delayed for at least some given number of seconds; these are
<STRONG>forked tasks</STRONG>.
<LI>

The <CODE>suspend()</CODE> function suspends the execution of the current task.  A
snapshot is taken of whole state of the execution, and the execution will be
resumed later.  These are called <STRONG>suspended tasks</STRONG>.
<LI>

The <CODE>read()</CODE> function also suspends the execution of the current task, in
this case waiting for the player to type a line of input.  When the line is
received, the task resumes with the <CODE>read()</CODE> function returning the input
line as result.  These are called <STRONG>reading tasks</STRONG>.
</UL>

<P>
The last three kinds of tasks above are collectively known as <STRONG>queued
tasks</STRONG> or <STRONG>background tasks</STRONG>, since they may not run immediately.

</P>
<P>
To prevent a maliciously- or incorrectly-written MOO program from running
forever and monopolizing the server, limits are placed on the running time of
every task.  One limit is that no task is allowed to run longer than a certain
number of seconds; command and server tasks get five seconds each while other
tasks get only three seconds.  This limit is, in practice, rarely reached.  The
reason is that there is also a limit on the number of operations a task may
execute.

</P>
<P>
The server counts down <STRONG>ticks</STRONG> as any task executes.  Roughly speaking, it
counts one tick for every expression evaluation (other than variables and
literals), one for every <SAMP>`if'</SAMP>, <SAMP>`fork'</SAMP> or <SAMP>`return'</SAMP> statement, and
one for every iteration of a loop.  If the count gets all the way down to zero,
the task is immediately and unceremoniously aborted.  By default, command and
server tasks begin with an store of 30,000 ticks; this is enough for almost all
normal uses.  Forked, suspended, and reading tasks are allotted 15,000 ticks
each.  

</P>
<P>
These limits on seconds and ticks may be changed from within the database, as
can the behavior of the server after it aborts a task for running out; see the
chapter on server assumptions about the database for details.

</P>
<P>
Because queued tasks may exist for long periods of time before they begin
execution, there are functions to list the ones that you own and to kill them
before they execute.  These functions, among others, are discussed in the
following section.

</P>
<P><HR><P>
Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_37.html">previous</A>, <A HREF="ProgrammersManual_39.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>.
</BODY>
</HTML>