tasks, processes, threads One of the main problems faced by embedded applications is how to assign processors to different tasks. In real-time operating systems, processes and threads are sometimes used instead of tasks. A process is a completely independent program with its own address space, which is a semi-independent program segment that executes within a process. Multiple threads share the address space of the owning process, and the expense of thread management is small.
-----------------------------
Thread Execution The most important behavior of the operating system when the application thread is dispatched and executed. As an example of a simple THREADX embedded operating system, threads are built by dynamically invoking tx_thread_create during the initialization phase or thread execution phase.
There are five states in the THREADX thread, i.e. ready, suspend, execute, stop, and finish. The order state of a thread refers to the time it is pending execution. The ordered thread will not be executed until it has the highest priority. When this happens, the ThreadX execution state has shifted to the executing thread.
① when a higher priority thread is in the order state, the executing line Cheng back to the ordered state. A new thread with a higher priority on the order state starts executing, and its state becomes execution. This mutual conversion between the ready state and the execution state occurs every time a thread preemption occurs.
② only one thread is in the execution state at any given moment.
③ threads that are in a suspended state cannot be used for execution, and the reason for thread hangs includes wait times, queue messages, time flags, memory, and basic thread hangs. Once the cause of the wait is removed, the thread re-enters the order state.
The ④ thread is in a stopped state and cannot be executed.
⑤ when a thread is established, it is assigned a value that represents its importance or priority.
⑥ can have the same priority in the program threads. At the same time, the priority of running threads can be changed.
⑦THREADX the scheduling of threads based on their precedence. The highest priority thread in the order state is first executed.
⑧ If multiple threads of the same priority are in the order state at the same time, they will be executed in first-in, in-and-out (FIFO) mode.
-----------------------------
Thread Scheduling Cyclic scheduling (Round-robin scheduling)
This service gives all ready threads with the same priority an opportunity to execute.
Time Slice (time-slicing)
A time slice is the maximum number of timer counts that a thread fully occupies the processor. When the time slice terminates, all other threads with the same or higher priority are given the opportunity to execute before the thread of the time slice has run out again.
Preemption (preemption)
Preemption refers to a process in which a higher-priority thread temporarily interrupts a running thread. This process is not visible to the executing thread. When a higher priority thread finishes executing, the control shifts back to the place where the first occurrence occurs. This is a very important feature in real-time systems because it can react quickly to important program events. A preemption portal allows a thread to define a priority limit that prohibits preemption. Priority above this limit is still allowed to preempt, while the lower priority is not allowed. Preemption can cause a number of problems, including thread starvation, overtime spending, priority inversion, deadlock, and so on.
-----------------------------
Thread Stack Area Each thread must have its own stack to hold its last executed content and to be used by the compiler. Most C compilers use stacks to invoke functions and also to place temporary local variables. The following figure shows a typical thread stack. How big the stack should be. This is a frequently asked question about threads. The stack area of the thread should be large enough to place the worst-case function call nesting, local variables, and storing the last execution.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.