Programs consist of a number of processes, each of which contains one or more conceptually concurrent threads of execution.
A thread is the unit of execution within a process. Every time a process is initialised a primary thread is created. For many applications the primary thread is the only thread that the application requires; however, processes can create additional threads.
Each user process has its own private address space, i.e. a collection of memory regions which that process can access. A user process cannot directly address memory areas in the address space of another process. There is also a special process, the Kernel process, whose threads run at supervisor privilege level. This process normally contains two threads:
the Kernel server thread, which is the initial thread whose execution begins at the reset vector, and which is used to implement all Kernel functions requiring allocation or deallocation on the Kernel heap
the null thread, which runs only when no other threads are ready to run. The null thread places the processor into idle mode to save power.
The address space of a process consists of a number of chunks, where a chunk is a region of RAM mapped into contiguous linear addresses. On creation, a user process contains one thread (the main thread) and one to three chunks; these are:
The stack/heap chunk; this contains the stack and the heap used by the main thread of the process. This chunk always exists.
The code chunk; this exists only if the process is loaded into RAM (i.e. it is not ROM resident).
The data chunk; this exists only if the process has static data.
If a process creates additional threads, then a new chunk is created for each new thread. Each chunk contains the thread's stack; if a new thread is not sharing an existing heap, then the chunk also contains a new heap.