The Execution Queue

The NCS/e can arrange several programs to run one after another.

Programs waiting to run are kept in the execution queue.

When a running program finishes, the first program waiting in the queue starts automatically. This continues until the queue is empty.

Once no more programs are waiting, control returns to the shell:

>

You can add programs to the queue using QUEUE and NEXT.

Adding a program to the queue

Use QUEUE followed by the name of a program to add it to the end of the execution queue.

For example:

> QUEUE GAME1

The program does not start immediately.

Instead, GAME1 is placed in the queue and the shell immediately presents another prompt:

>

You can continue entering commands.

If you add several programs:

> QUEUE GAME1
> QUEUE GAME2
> QUEUE GAME3

they wait in the same order:

Position Program
1 GAME1
2 GAME2
3 GAME3

GAME1 will run first, followed by GAME2, and then GAME3.

Starting queued programs

There is no separate command to start the execution queue.

Instead, use RUN to start a program normally:

> RUN START

START begins immediately.

When START finishes, the first program in the queue begins automatically.

With the queue above, the programs therefore execute in this order:

START
GAME1
GAME2
GAME3

After GAME3 finishes, nothing remains in the queue, so control returns to the shell.

Putting a program next

Sometimes you want to add a program that should run before the programs already waiting.

Use NEXT followed by the program name:

> NEXT GAME0

NEXT adds the program to the beginning of the execution queue instead of the end.

For example, suppose you enter:

> QUEUE GAME2
> QUEUE GAME3
> NEXT GAME1

The queue now contains:

Position Program
1 GAME1
2 GAME2
3 GAME3

Starting another program:

> RUN START

therefore produces the following execution order:

START
GAME1
GAME2
GAME3

Both QUEUE and NEXT return immediately to the shell. They arrange programs for later; they do not start them.

When a program stops

What happens to the queue depends on how the current program stops.

Normal completion

When a program reaches the end normally, the next program in the queue starts automatically.

If the queue is empty, control returns to the shell.

ABORT

Pressing ABORT, or Ctrl+C, stops the current program.

It does not clear the execution queue.

If another program is waiting, that program begins immediately. If the queue is empty, control returns to the shell.

For example, suppose the programs are running in this order:

START
GAME1
GAME2
GAME3

If you press ABORT while GAME1 is running, GAME1 stops and GAME2 begins.

GAME3 remains waiting after it.

Fatal error

A fatal error stops the current program and clears the execution queue.

Queued programs are not started after a fatal error. Instead, the error is displayed and control returns to the shell.

The behavior can be summarized as:

Current program What happens next
Finishes normally Run the next queued program
Stopped with ABORT Run the next queued program
Encounters a fatal error Clear the queue and return to the shell

If no program is waiting when a program finishes normally or is stopped with ABORT, control simply returns to the shell.

Program arguments

QUEUE and NEXT can also provide arguments to the programs they add.

For example:

> QUEUE PROGRAM argument1 argument2

The arguments are kept with the queued program and are provided when that program eventually starts.

A queued program may receive up to eight arguments.

Arguments and alternate program entry points are covered in Program Arguments and Entry Points.