Every task on a DSP starts by invoking its main function as a thread. A thread is a sequence of instructions that can run in parallel with other threads. Threads may dynamically create any number of new thread, limited only by the available memory.
Each thread shares code and static data with other threads in a task, but has it's own stack (workspace). Once created, a thread is completely independent of the thread that created it.
As a DSP can execute only one sequence of instructions at a time, the kernel arranges to share the available CPU cycles among the active threads by "context switching" from one thread to another. A context switch occurs when:
Â
- the active thread waits for something (a semaphore, event, timer, or interrupt)
-
the active thread explicitly relinquishes the CPU (thread_deschedule)
-
the active thread has been running continuously for a certain time (a time slice)
-
a thread of higher priority than the active thread becomes ready to execute (pre-emption)
Â
Threads have a priority from 0 to 7, with 0 being the highest priority. Threads of priority 0 are known as urgent threads and are never time-sliced or pre-empted.
Â




