Difference between revisions of "Lib/sequencer offers Multitasking"

From Liberty Eiffel Wiki
Jump to navigation Jump to search
(still translating)
(still translating)
Line 43: Line 43:
 
* '''Network''': this allows to build tasks waiting network connections (features <tt>when_connection</tt> and <tt>is_connection</tt>).
 
* '''Network''': this allows to build tasks waiting network connections (features <tt>when_connection</tt> and <tt>is_connection</tt>).
   
  +
== Tasks unfolding ==
<!--
 
== Le déroulement des tâches ==
 
   
  +
The manager implements the following cycle:
Le gestionnaire implante le cycle suivant&nbsp;:
 
   
* appel de la méthode [[library_class:READY_DESCRIPTION|<tt>READY_DESCRIPTION</tt>]].<tt>reset</tt>&nbsp;;
+
* call to the feature [[library_class:READY_DESCRIPTION|<tt>READY_DESCRIPTION</tt>]].<tt>reset</tt>;
* appel de la méthode <tt>prepare</tt> sur chaque tâche&nbsp;;
+
* call to the feature <tt>prepare</tt> on each task;
* appel de la méthode [[library_class:READY_DESCRIPTION|<tt>READY_DESCRIPTION</tt>]].<tt>wait</tt> pour attendre qu'au moins une des conditions se réalise&nbsp;;
+
* call to the feature [[library_class:READY_DESCRIPTION|<tt>READY_DESCRIPTION</tt>]].<tt>wait</tt> to wait for at least one condition to happen;
* appel de la méthode <tt>is_ready</tt> sur chaque tâche&nbsp;;
+
* call to the feature <tt>is_ready</tt> on each task;
* pour chaque tâche prête, appel de la méthode <tt>continue</tt>&nbsp;;
+
* for all the ready tasks, call to the feature <tt>continue</tt>;
* sur ces mêmes tâches, appel de la méthode <tt>done</tt> et le cas échéant, suppression de la tâche de la boucle&nbsp;;
+
* for those tasks, call to the feature <tt>done</tt> and if relevent, removal of the task;
  +
* and back to the beginnine.
* et on recommence.
 
   
  +
<!--
 
== Les priorités ==
 
== Les priorités ==
   

Revision as of 14:52, 4 January 2006

*** OK, I'm translating that --Cyril 14:34, 4 Jan 2006 (CET)

The lib/sequencer library implements one kind of cooperative multi-tasking of the event-driver kind. Unlike "pure" cooperative multi-tasking, a task cannot stop at any time (using an hypothetic yield feature) but only in lnown and stable states. That is conform to the Eiffel principles.

The principle is:

  • the class LOOP_STACK manages the multi-tasking;
  • the class JOB represents a task. The task core is the continue feature, in which the task controls the whole system;
  • the class READY_DESCRIPTION allows to describe in which conditions a task can be executed.

We will successively see each of those concepts.

The multi-tasking manager

The class LOOP_STACK is in charge of managing the multi-tasking. It is used in two steps:

  • initialisation: creation of the LOOP_STACK object, and adding of the tasks to execute
  • execution: execution of the run feature

Of course, tasks can be added during the execution. The manager can also be stopped, thanks to the break feature.

Also, the loops stack is composed of many execution loops (LOOP_ITEM). This allows, for instance, the implementation of a kind of modality (see the modal windows in Vision).

Tasks

A task has a life cycle represented by the features executed by the manager (indeed a LOOP_ITEM hence the export clauses of those fetaures).

  1. prepare allows to prepare the task; in this phase, the task sets the events upon which it wants to be activated. The READY_DESCRIPTION object is an object upon which one can set conditions (thanks to its when_* features).
  2. is_ready allows to test if the task has really been activated.The READY_DESCRIPTION object is an object upon which one can test conditions (thanks to its is_* features).
  3. continue contains the execution body of the task, and is executed if the task is really activated.
  4. done tells if the task has finished its execution. If so, it will be removed from the execution loop. Otherwise, the cycle begins again.
  5. restart allows to reinsert a task in the execution loop.

The restart feature is seldom useful. See Vision for some use cases.

Execution conditions

The class READY_DESCRIPTION allows to set and test conditions. The possible conditions are:

  • Time: this allows to create periodic tasks. See the classes PERIODIC_JOB and BACKGROUND_JOB;
  • Input-output:
    • Data on an input stream: this allows to build tasks that wait for input data to be available (features when_data and is_data),
    • Data on an output stream: this allows to build tasks that wait until they can write on an output stream (features when_free and is_free) ;
  • Network: this allows to build tasks waiting network connections (features when_connection and is_connection).

Tasks unfolding

The manager implements the following cycle:

  • call to the feature READY_DESCRIPTION.reset;
  • call to the feature prepare on each task;
  • call to the feature READY_DESCRIPTION.wait to wait for at least one condition to happen;
  • call to the feature is_ready on each task;
  • for all the ready tasks, call to the feature continue;
  • for those tasks, call to the feature done and if relevent, removal of the task;
  • and back to the beginnine.