suspend_thread

Definition: suspend_thread(atom hThread)
Description: Suspend execution of a thread.
Comments: This method is intended primarily for use in multitasking, which is implemented in phix as a collection of threads, all but one of which are suspended at any given moment. Therefore locking is not required, which makes multitasking simpler than multithreading, but should any task stall, for instance waiting for a network connection, then the entire app stalls, a problem which does not afflict multithreading.

Generally speaking the only sensible use of suspend_thread() is by the thread itself, since arbitrarily suspending another active thread is quite likely to lead to deadlock.

In the phix implementation of multitasking, when a task invokes task_yield(), assuming that there is indeed another task that control should now be transfered to, it invokes resume_thread() on that other thread(/task), before invoking suspend_thread() on itself. Of course the line of code immediately following suspend_thread(me) is only ever executed if somebody else graciously invokes resume_thread(you).

The thread handles used in builtins\VM\pTask.e are private to that module, which thankfully prevents accidentally invoking suspend_thread() on one of them, which without anything still running to invoke resume_thread() would effectively stop all running tasks permanently.
See Also: multitasking, task_yield, resume_thread