Function - Cause context switch with options.
kern_return_t thread_switch (mach_port_t new_thread, int option, mach_msg_timeout_t time);
The thread_switch function provides low-level access to the scheduler's context switching code. new_thread is a hint that implements hand-off scheduling. The operating system will attempt to switch directly to the new thread (bypassing the normal logic that selects the next thread to run) if possible. Since this is a hint, it may be incorrect; it is ignored if it doesn't specify a thread on the same host as the current thread or if the scheduler cannot switch to that thread (i.e., not runable or already running on another processor). In this case, the normal logic to select the next thread to run is used; the current thread may continue running if there is no other appropriate thread to run.
The option argument specifies the interpretation and use of time.
The possible values (from \*L
The minimum time and units of time can be obtained as the min_timeout
value from the HOST_SCHED_INFO flavor of host_info.
thread_switch is often called when the current thread
can proceed no further
for some reason; the various options and arguments allow information about
this reason to be transmitted to the kernel. The new_thread
argument (hand-off
scheduling) is useful when the identity of the thread that must make progress
before the current thread runs again is known. The SWITCH_OPTION_WAIT
option is used when the amount of time that the current thread
must wait before it
can do anything useful can be estimated and is fairly short,
especially when the
identity of the thread for which this thread must wait is not known.
Users should beware of calling thread_switch with an
invalid hint (e.g., THREAD_NULL) and no option.
Because the time-sharing scheduler varies the
priority of threads based on usage, this may result in a waste
of CPU time if the
thread that must be run is of lower priority. The use of the
SWITCH_OPTION_DEPRESS option in this situation is highly recommended.
thread_switch ignores policies. Users relying on the
preemption semantics of a
fixed time policy should be aware that thread_switch
ignores these semantics;
it will run the specified new_thread independent of its scheduling
attributes and
those of any threads that could run instead.
Only generic errors apply.
Functions:
thread_abort,
thread_depress_abort.
NOTES
CAUTIONS
RETURN VALUES
RELATED INFORMATION