The Croc Programming Language
Threads

Functions

word_t croc_thread_new (CrocThread *t, word_t func)
 
CrocThreadState croc_thread_getState (CrocThread *t)
 
const char * croc_thread_getStateString (CrocThread *t)
 
uword_t croc_thread_getCallDepth (CrocThread *t)
 
void croc_thread_reset (CrocThread *t, word_t slot)
 
void croc_thread_resetWithFunc (CrocThread *t, word_t slot)
 
void croc_thread_halt (CrocThread *t)
 
void croc_thread_pendingHalt (CrocThread *t)
 
int croc_thread_hasPendingHalt (CrocThread *t)
 

Detailed Description

Functions which operate on threads.

Function Documentation

word_t croc_thread_new ( CrocThread t,
word_t  func 
)

Creates and pushes a new thread object in this VM, using the script function at func as its main function.

The new thread will be in the initial state and can be started by calling it like a function.

Returns
the stack index of the pushed value.
CrocThreadState croc_thread_getState ( CrocThread t)
Returns
the execution state of the given thread.
const char* croc_thread_getStateString ( CrocThread t)
Returns
a string representation of the execution state of the given thread. This is a constant string, so it's safe to store a pointer to it.
uword_t croc_thread_getCallDepth ( CrocThread t)
Returns
the call depth of the given thread. This is how many function calls are on the call stack. Note that there can be more calls than are "actually" on it, since this function also counts tailcalls.
void croc_thread_reset ( CrocThread t,
word_t  slot 
)

Resets a dead thread at slot to the initial state, keeping the same main function.

void croc_thread_resetWithFunc ( CrocThread t,
word_t  slot 
)

Resets a dead thread at slot to the initial state, but changes its main function to the script function that is on top of the stack.

The function is popped.

void croc_thread_halt ( CrocThread t)

Halts the given thread.

If the thread is currently running, immediately throws a HaltException on it. Otherwise, it places a pending halt on the thread (see croc_thread_pendingHalt).

void croc_thread_pendingHalt ( CrocThread t)

Places a pending halt on the thread.

The thread will not halt immediately, but as soon as it begins executing script code, it will.

int croc_thread_hasPendingHalt ( CrocThread t)
Returns
nonzero if there is a pending halt on the given thread.