Download VisualDSP++ Kernel (VDK) User's Guide

Transcript
Threads
Threads
When designing an application, you partition it into threads, where each
thread is responsible for a piece of the work. Each thread operates independently of the others. A thread performs its duty as if it has its own
processor, but can communicate with other threads.
Thread Types
You do not directly define threads; instead, you define thread types. A
thread is an instance of a thread type, and is similar to any other
user-defined type. In other words, a thread type is a C structure, and every
variable of the structures is a thread.
You can create multiple instantiations of the same thread type. Each
instantiation of the thread type has its own stack, state, priority, and other
local variables. Each thread is individually identified by its ThreadID, a
handle that can be used to reference that thread in kernel API calls. A
thread can gain access to its ThreadID by calling GetThreadID(). A
ThreadID is valid for the life of the thread—once a thread is destroyed, the
ThreadID becomes invalid.
Old ThreadIDs are eventually reused, but there is significant time between
a thread’s destruction and the ThreadID re-use: other threads have to recognize that the original thread is destroyed.
Thread Parameters
When a thread is created, the system allocates space in the heap to store a
data structure that holds the thread-specific parameters. The data structure contains internal information required by the kernel and the thread
type specifications provided by the user.
4-2
VisualDSP++ Kernel (VDK) User’s Guide