Program Contains several processes, each of which contains one or more threads that are conceptually known for execution.
A thread is the execution unit of a process. After the process is initialized, the main thread is created. For most applications, only one main thread is required. Even so, the process can also create additional threads.
Each user process has its own private address space, that is, the process has a certain memory area that can be accessed by it. A user process cannot directly access the address space of other processes. There is also a special process, the kernel process, which runs in the superuser permission mode. This process usually includes two threads:
Kernel server (kernel server) thread: It is an initial process that exists at system startup. It can be executed in heap by the core function request memory allocation or memory redistribution. This is the thread with the highest permissions in the system.
NULL (null) thread:When there are no other running threads in the system, this thread starts to run. The null thread makes the processor idle, reducing power consumption.
The thread runs independently and does not know that there are other threads in the process. Thread execution is preemptible. That is to say, the currently running thread may be suspended at any time so that another thread can run.
Priority is set for each thread. At any time, as long as the thread is ready, a thread with a high priority always runs first. If the thread has the same leisurely permission, rotate the scheduling based on the time slice. Context switching includes saving and restoring the thread state. This status not only contains the Processor register (process context), but also contains the address space (process context) that the thread can access ). Process context is switched only when rescheduling is performed between two processes.
Compared with the activity object, the activity object allows non-strong multi-task scheduling in a thread.
A thread can be suspended, wake up, throws exceptions, and ends other threads.
After a thread is created, it is suspended. It does not enter the running status immediately until its resume () member function is called.
After a thread is created, it has the default preferred level of eprioritynormal. The thread is initialized and suspended, which means that the running priority of the thread can be changed before the thread starts running (by calling rthread: setpriority ()).
The original article is as follows:
Introduction to threads and processes
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 each application the primary thread is the only one 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. this is the highest priority thread in the system.
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.
Threads execute individually and are unaware of other threads in a process. the scheduling of threads is pre-emptive, I. e. A currently executing thread may be susponded at any time to allow another thread to run.
Each thread is assigned a priority; at any time, the thread running is the highest priority thread which is ready to run. threads with equal priority are time-sliced on a round-robin basis. context switching between threads involves saving and restoring the State of threads. this state has des not only the processor registers (the thread context) but also the address space accessible to the thread (the process context ). the process context only needs switching if a reschedule is between threads in different processes.
Compare this with active objects which allow non pre-emptive multi-tasking within a single thread.
A thread can suspend, resume, panic and kill another thread.
When a thread is created it is put into a susponded state, it does not begin to run until that thread's resume () member function is called.
When a thread is created, it is given the priority eprioritynormal by default. the fact that a thread is initially put into a susponded State means that the thread priority can be changed (rthread: setpriority () before the thread is started (rthread :: resume ()).