typedef struct CthThreadStruct *CthThread;
This is an opaque type defined in converse.h. It represents
a first-class thread object. No information is publicized about the
contents of a CthThreadStruct.
typedef void (CthVoidFn)();
This is a type defined in converse.h. It represents
a function that returns nothing.
typedef CthThread (CthThFn)();
This is a type defined in converse.h. It represents
a function that returns a CthThread.
CthThread CthSelf()
Returns the currently-executing thread. Note: even the initial
flow of control that inherently existed when the program began
executing main counts as a thread. You may retrieve that thread
object using CthSelf and use it like any other.
CthThread CthCreate(CthVoidFn fn, void *arg, int size)
Creates a new thread object. The thread is not given control
yet. To make the thread execute, you must push it into the
scheduler queue, using CthAwaken below. When (and if) the thread
eventually receives control, it will begin executing the specified
function fn with the specified argument. The size
parameter specifies the stack size in bytes, 0 means use the default
size. Caution: almost all threads are created with CthCreate, but not
all. In particular, the one initial thread of control that came into
existence when your program was first exec'd was not created
with CthCreate, but it can be retrieved (say, by calling CthSelf in main), and it can be used like any other CthThread.
CthThread CthCreateMigratable(CthVoidFn fn, void *arg, int size)
Create a thread that can later be moved to other processors.
Otherwise identical to CthCreate.
This is only a hint to the runtime system; some threads implementations cannot migrate threads, others always create migratable threads. In these cases, CthCreateMigratable is equivalent to CthCreate.
CthThread CthPup(pup_er p,CthThread t)
Pack/Unpack a thread. This can be used to save a thread to disk,
migrate a thread between processors, or checkpoint the state of a thread.
Only a suspended thread can be Pup'd. Only a thread created with CthCreateMigratable can be Pup'd.
void CthFree(CthThread t)
Frees thread t. You may ONLY free the
currently-executing thread (yes, this sounds strange, it's
historical). Naturally, the free will actually be postponed until the
thread suspends. To terminate itself, a thread calls
CthFree(CthSelf()), then gives up control to another thread.
void CthSuspend()
Causes the current thread to stop executing.
The suspended thread will not start executing again until somebody
pushes it into the scheduler queue again, using CthAwaken below. Control
transfers to the next task in the scheduler queue.
void CthAwaken(CthThread t)
Pushes a thread into the scheduler queue. Caution: a thread
must only be in the queue once. Pushing it in twice is a crashable
error.
void CthAwakenPrio(CthThread t, int strategy, int priobits, int *prio)
Pushes a thread into the scheduler queue with priority specified by
priobits and prio and queueing strategy strategy.
Caution: a thread
must only be in the queue once. Pushing it in twice is a crashable
error. prio is not copied internally, and is used when the scheduler
dequeues the message, so it should not be reused until then.
void CthYield()
This function is part of the scheduler-interface. It simply
executes { CthAwaken(CthSelf()); CthSuspend(); } . This combination
gives up control temporarily, but ensures that control will eventually
return.
void CthYieldPrio(int strategy, int priobits, int *prio)
This function is part of the scheduler-interface. It simply
executes
{CthAwakenPrio(CthSelf(),strategy,priobits,prio);CthSuspend();}
This combination
gives up control temporarily, but ensures that control will eventually
return.
CthThread CthGetNext(CthThread t)
Each thread contains space for the user to store a ``next'' field (the
functions listed here pay no attention to the contents of this field).
This field is typically used by the implementors of mutexes, condition
variables, and other synchronization abstractions to link threads
together into queues. This function returns the contents of the next field.
void CthSetNext(CthThread t, CthThread next)
Each thread contains space for the user to store a ``next'' field (the
functions listed here pay no attention to the contents of this field).
This field is typically used by the implementors of mutexes, condition
variables, and other synchronization abstractions to link threads
together into queues. This function sets the contents of the next field.
June 29, 2008
Converse Homepage
Charm Homepage