Thread control, Name, Synopsis – Comtrol eCos User Manual
Page 47: Description, Yield, Delay
Thread control
Name
cyg_thread_yield, cyg_thread_delay, cyg_thread_suspend, cyg_thread_resume,
cyg_thread_release
— Control whether or not a thread is running
Synopsis
#include
<
cyg/kernel/kapi.h
>
void cyg_thread_yield(void);
void cyg_thread_delay(cyg_tick_count_t delay );
void cyg_thread_suspend(cyg_handle_t thread);
void cyg_thread_resume(cyg_handle_t thread);
void cyg_thread_release(cyg_handle_t thread);
Description
These functions provide some control over whether or not a particular thread can run. Apart from the required use of
cyg_thread_resume
to start a newly-created thread, application code should normally use proper synchronization
primitives such as condition variables or mail boxes.
Yield
cyg_thread_yield
allows a thread to relinquish control of the processor to some other runnable thread which has
the same priority. This can have no effect on any higher-priority thread since, if such a thread were runnable, the
current thread would have been preempted in its favour. Similarly it can have no effect on any lower-priority thread
because the current thread will always be run in preference to those. As a consequence this function is only useful
in configurations with a scheduler that allows multiple threads to run at the same priority, for example the mlqueue
scheduler. If instead the bitmap scheduler was being used then
cyg_thread_yield()
would serve no purpose.
Even if a suitable scheduler such as the mlqueue scheduler has been configured,
cyg_thread_yield
will still
rarely prove useful: instead timeslicing will be used to ensure that all threads of a given priority get a fair slice
of the available processor time. However it is possible to disable timeslicing via the configuration option
CYGSEM_KERNEL_SCHED_TIMESLICE
, in which case
cyg_thread_yield
can be used to implement a form of
cooperative multitasking.
Delay
cyg_thread_delay
allows a thread to suspend until the specified number of clock ticks have occurred. For ex-
ample, if a value of 1 is used and the system clock runs at a frequency of 100Hz then the thread will sleep for up
to 10 milliseconds. This functionality depends on the presence of a real-time system clock, as controlled by the
configuration option
CYGVAR_KERNEL_COUNTERS_CLOCK
.
47