PREV UP next StackThreads/MP: version 0.77 User's Guide

3.9.4: Deschedule Worker

        void st_yield_os_thread()
@        void st_sleep_os_thread_ms(ms)
@                int ms;

st_yield_os_thread() instructs the operating system to temporarily deschedule the calling worker (not thread). Recall that in general many threads are running on top of a worker. Descheduling a worker effectively deschedules all threads that are running on top of it.

The exact effect depends on the operating system and the underlying execution machinery of OS-level threads. Specifically, it is likely to have no effects when the number of workers are less than the number of available CPUs.

st_sleep_os_thread_ms(ms) instructs the operating system to deschedule the calling worker (not thread) for ms microseconds.

Use these APIs only when you understand how StackThreads/MP works and you are sure they are really necessary. Specifically, it is usually a bad idea to call these primitives to achieve a synchronization. You should normally suspend the current thread (not the entire worker) and explicitly resume it when it can make a further progress.