Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ thread(2) — Stardent 3.0 System Software

Media Vault

Software Library

Restoration Projects

Artifacts Sought

THREAD(2)  —  Stardent Computer Inc. (System Calls)

NAME

thread − create, terminate, suspend, or resume threads in a process

SYNTAX

int thread(enum thread_functions, int );

DESCRIPTION

thread is used to control the allocation and execution of threads.  The thread_function argument describes the desired action.  int is mandatory and its value and its use are dependent upon the specified thread_function argument.  The thread_function arguments are:

THREAD_CREATE
Creates a number of threads, chosen by the system for best performance. Typically, this number is equal to the number of processors available. int argument is ignored.  The return value for each thread is the number created.  Returns −1 on an error. 

THREAD_CREATEN
Creates int number of arguments.  Typically, this number is equal to the number of processors available.  The return value for each thread is the number created.  Returns −1 on an error. 

THREAD_JOIN Forces all threads to be terminated and the parent revives.  int argument is ignored.  Returns zero on completion. 

THREAD_SUSPEND
Halts all peer threads, but preserves their state. Leaves only one thread running. int argument is ignored. 

THREAD_RESUME
Resumes execution of halted peer threads. int argument is ignored. 

THREAD_NPROC
Returns as the value of the function the number of processors available.  This is the number of processors that would be assigned with use of THREAD_CREATE. int argument is ignored. 

Associated Functions

The following functions are used in the manipulation of threads. 

void threadserial() Forces all other threads to become idle.  After the function is executed, the process is serial. 

thread_new(p,n,TYPE)
A macro that assigns to p, a pointer, new storage sufficient to hold n objects of type TYPE.

thread_free(p) A macro that frees storage allocated by thread_new. p is a pointer to the storage. 

void parbegin(n) Marks the beginning of a parallel section of code that splits into n microtasks.  This can also be used, with low overhead, to redispatch idled threads. 

int parnext() Initiates a microtask in the parallel section of code.  It returns the microtask number from n to 1 When there are no further microtasks, parnext idles all threads but one.  When all other threads complete their tasks, parnext returns zero. 

void parstack( void (∗)(), int, int )
The first argument is a function, the second argument is a stack_size, and the third argument is some number of threads.  parstack requests that some number of available threads each independently execute a call to a function. Each call to the function is done on a separate stack of size stack_size. If number is zero, the natural number of processors is used.  When all other threads complete their tasks, parstack returns zero. 

Variables and Macros

The following variables and macros are also available. 

extern int _procno Variable used with parbegin, parnext, and parstack that allows you to keep track of the thread that is currently executing. 

extern int _taskno Variable used only with parstack. Its value ranges from zero to n−1, where n is the parstack argument. 

extern volatile int thread_system
Variable used as a semaphore that gates system calls. This allows only one system call at a time per process.

THREAD_SYS(S) This macro synchronizes statement S with the thread_system semaphore. 

LOAD_SYNCH(v) This macro expands into a load-and-synch operation on location v.

PROTECT(v,S) This macro specifies that statement S is only done after the thread owns the semaphore v. v must be initialized to 1. 

FILES

/usr/include/thread.h

September 29, 2021

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026