FTE MULTITHREADED

From FTE
Jump to: navigation, search

Description

Three new builtins that control a sort of multithreaded behaviour.

fork: Derived from a unix function, the fork command splits the QuakeC call stack into two. This function is called once but returns twice in a fit of wierdness. All local variables are preserved and identical on each side of the fork. However, if the thread returning first alters any globals, they will be altered when the second thread returns. The two globals self and other are always preseved. Be cautious, because self could potentially have been removed by the first thread.

abort: This is a fairly useful function, that stops the QuakeC execution in it's tracks. Essentually, it 'returns' from all the functions on the call stack, and stops when it gets to the engine functions. The parameter passed in is the return value it uses to the engine (It is advisable to use 0 as the argument). This function can be used in the event of a partially recoverable error. If you can correct the error, but don't want to test if all the functions on the stack had one, use the abort function. The other use of this function is on the second side of a fork call. At times it may be useful to fork into a two threads, continue with one and abort the second after a certain ammount of time.

sleep: Causes the current 'thread' to stop processing for a specified ammount of time. When the thread has reawoken, it will continue as before with the same locals, and self/other globals. Other globals will not be preserved. By forking and sleeping, you can create a sort of think function, which would be more convinient in many cases. This function is REALLY useful when you need to break up a function because it causes lag or trips the infinate loop counter (quess comes to mind).

Threads resume just before the StartFrame QC function is called, assuming they have slept for long enough.

Builtins

float() fork = #210;
void(...) abort = #211;
void(float secs) sleep = #212;