Next: Handling C++ Up: Implementation Previous: Select Implementation

Scheduling

 

The C-with-Ease implementation can operate with a wide variety of levels of system support for process scheduling, from fully preemptive processes to coroutines requiring explicit context switches.

Each completely separate process address space we call a cell. Each cell may contain 0 or more C-with-Ease processes. Each process within a cell we call a thread. Systems where threads may run simultaneously (on multiple physical processes) or where context switches may occur at any stage of execution are preemptive. Where context switches must be explicitly requested by the thread, they are non-preemptive.

Messages are logically handled by the cell, not by the individual threads that they are directed towards.

A thread is reused when the Ease process that is using it finishes. This improves efficiency, as it reduces the frequency of thread creation and descrition. It also improves portability, as some threads libraries do not have facilities for removing threads.

The library associates an integer identifier and a structure with each thread. The thread structure contains the following:

Non-Preemptive Threads

In a non-preemptive system, the C-with-Ease library controls all context switches. An attempt is made to keep the number of context switches to a minimum by only switching when the current thread can no longer run. Messages (in a multi-cell system) are received and handled by the cell (in the guise of the currently executing thread) on behalf of all threads (and contexts).

A list of runnable threads is kept, and when a thread becomes unblocked it is added to this list. If the current thread blocks, a thread is removed from the runnable list and switched to. If there are no runnable threads then the cell blocks and waits for a message. If the host consists of a single cell and all threads in that cell block then the Ease programmer has produced deadlock. The library reports this and aborts the program.

Preemptive Threads

In a preemptive system concurrent access to shared resources (such as contexts and process structures) must be prevented. A mutex and a semaphore are added to the process structure to achieve this. (A context only has a mutex).

The mutex is for short term locking of the process. It prevents other threads from locking the process (and thereby accessing it) while the lock is held. A mutex may be locked multiple times by the same process and must be unlocked a corresponding number of times.

The semaphore is used for suspending and resuming the thread. The thread waits on the semaphore and another thread signals it to allow the waiting thread to resume. It is possible, and legal, for the signal to precede the wait.

A list of running (and runnable) threads is not kept, the host or the host interface is expected to take care of it. Any thread which is not waiting on a semaphore or waiting for a lock on a mutex is eligible to run.

Scheduler Interface

The scheduler provides the following services to the Ease library:

Next: Handling C++ Up: Implementation Previous: Select Implementation



Tim MacKenzie <tym@cs.monash.edu.au>
Mon Apr 1 00:27:29 EST 1996