next up previous contents index
Next: Local and global variables Up: Threads Previous: Threads   Contents   Index


Creation of threads

A program can be executed as a thread by using the command thread. For example

- interpcom -> thread th_0 prog0

will execute the program prog0 (which must be already loaded). Here th_0 is the name of the thread. The command interpreter can then receive and execute other commands. It is of course possible to execute several threads from the main stream or from other threads. The thread is finished when the corresponding program is. If the thread program does not run silently, the successive instructions as well as the messages will be printed. It is possible to give arguments to the program. For instance :

- interpcom -> thread th_0 prog0 arg1 arg2 arg3

The necessary informations that are used to run programs are stored in a flow_data structure

typedef struct _flow_data {
    int              MODE_FONCT_;
    int              I__COM_CUR;
    int              I_LIGNE_CUR;
    int              I_LEC_CUR;
    int              I_SPEED;
    char            *HCOM;
    int              IS_COM;
    int              PRLEVEL;
    int              IND_COM;
    char            *_H_LIGNE;
    char           **_ARGV_C;
    int              _ARGC_C;
    char            *CMDX;
    int              CURVOICE;
    int              HORLOGE;
    long             I_TIME_X;
    long             _I_TIME_X;
    int              PR_COM;
    int              IX_COM;
    FILE           **INP;
    int             *ARGC_X;
    argv_t          *ARGV_X;
    FILE            *MON_FILE;
    int              I_COM;
    char           **COM_PREC;
    XVARIABLE       *VARS;
    double	    *VARS2;
    char            *name;
    int              used;
    int              thread;
    char           **extra;
    char	   **h;
    char            *var;
    int              num;
    int              pause;
    int              mutex_obj;
    int		     parse_com;
    int		     kill;
    int		     n_instr;
} flow_data;

Each thread is associated to such a structure. The command interpreter itself (which receives the commands of the user) is also considered as a thread (the main thread) and uses a flow_data structure.

For instance :

- the member MODE_FONCT_ is the running mode in which the thread program is running.

- the member MON_FILE is the monitor file (if any) that is used.

- the member name is the name of the thread.


Four other commands are related to threads :

listt will give the list of all the running threads. For example, if the preceeding thread th_0 is running, we obtain

- interpcom -> listt
0 ------| main
1 ------| th_0

(thread number 0 is the main thread).


pause can be used to stop the execution of a thread. For instance

- interpcom -> pause th_0 1

will stop the execution of the thread th_0. More precisely the program will stop just after the instruction that was executed when the pause command was given. It is possible to continue the execution of the thread with the same command, with argument 0 :

- interpcom -> pause th_0 0

The command pause will not be accepted by the interpreter if only one thread (i.e. the main thread) is running.


wait can also be used to stop the execution of a thread, depending on the value of a global variable. For instance

- interpcom -> wait th_0 _x

will stop the execution of the thread th_0 if the global variable _x is undefined or if its value is less than or equal to zero. If its value becomes positive (with an instruction _x=1 for example, in another thread) then the thread th_0 will go on. As for pause, wait will not be accepted if only one thread is running.


kill can be used to kill a thread. For instance

- interpcom -> kill th_0

will kill the thread th_0. More precisely the program will stop just after the instruction that was executed when the kill command was given.


next up previous contents index
Next: Local and global variables Up: Threads Previous: Threads   Contents   Index
2009-11-12