当前位置:网站首页>A possible cause and solution of "stuck" main thread of RT thread
A possible cause and solution of "stuck" main thread of RT thread
2022-07-06 11:59:00 【Weiyuan escort agency】
Write it at the front
The current bare metal programs can no longer meet the code structure requirements of embedded robots , Because the system of an embedded robot is very huge , By Perception algorithm , Decision algorithm and control algorithm Other components , This does not include some programs that need to be connected . Huge code needs A chip level operating system to shield the impact of hardware on the upper Algorithm , At the same time, it provides API, Help the upper algorithm call the lower hardware , Therefore, a chip level operating system is very important , and RT-Thread It is a domestic chip level operating system , And my course just involves the system , So I'm going to write a series of blogs to record all kinds of problems in the process of learning this operating system , I hope I can bring you some help ~
Problem phenomenon
This semester we are taking embedded courses , Learned a new lightweight operating system ——RT-Thread( Hereinafter referred to as rtt), This is a domestic operating system , The characteristic of this operating system is Only the thread , No process , If we want to use this system, we only need to operate the corresponding thread , Then the way we use this system well is very simple , We just need Realize the coordination work between various threads That's all right. . Get down to business , Before I learn this rtt I have a problem , That's it When I am main Functional while(1) Nothing in it , When running , The whole chip went down , Code as shown
Reasons and solutions
The detour we took
At the beginning, I thought the reason was in my whole project main Threads have a high priority , Other threads Is the lowest priority ( What I set up here is 25), When scheduling threads High priority threads will be scheduled first ,main Thread is the highest priority thread in my system , And it is in hurry in vain A thread of , So that is This main Threads are always occupying system resources , No other thread can be scheduled , Therefore, there is a phenomenon similar to system downtime . At this point, I have to talk about our picture rtt The state flow diagram of thread scheduling of the system
In ordinary operating system , The flow between these States is relatively easy to understand , But in rtt in , It is different from other operating systems , I have already mentioned this before , That's it It has no process Of this thing , So in rtt Operating system , Ready state = Running state . That is to say... In the picture 2 The cycle represented by the circle is equivalent . however , So there's a problem , Because if you follow my logic , Not just hurry in vain main Thread while(1) There will be system downtime when , Even if the main Thread while(1) The task program is added , Then our whole rtt The system also depends on the system Scheduling mechanism of process ( High priority threads must be scheduled first ) To call repeatedly main In the thread while(1) Tasks inside , Similarly, other threads will not be called , That's not gonna work , So I went to rtt Search the official website of , Finally, the mystery behind this problem is solved .
See light suddenly
First, let's rtt System Define some concepts Let's take the following code segment as an example
void thread_entry(void* paramenter) {
/* Wait for the event to happen */
/* Service events 、 To deal with */
}
Thread ready / function
This code is the entity function of the thread , that rtt How will the system execute this program at that time ? Let me draw an image to explain to you
If this thread High priority Words ,rtt The system will always execute this thread , It will not execute other threads , Because the thread will enter be ready state , And because this thread has Highest priority , So after entering the thread scheduling pool, it will be scheduled to run again , Get into function state , But in rtt in , actually ( In the process of implementation ) Thread does not exist running state , Ready state and running state are equivalent , But it is more convenient to understand the mechanism according to the above .
Thread hanging
rtt The official website has a relatively detailed , clear Description of , I made a move here , Invasion and deletion
The important thing in this paragraph is this sentence , Threads do not participate in scheduling , That is, no matter how high the priority of the thread is , He will not enter the thread scheduling pool , According to the description in the table , The conditions that cause the thread to hang are 2 individual
- 1. Resource not available
- 2. Threads actively delay for a period of time
solve the problem
main A thread is a special thread , So he must also meet rtt System management thread mechanism . Then our problem is well explained . When main Thread while(1) The program in the loop does not Resource unavailability occurs perhaps Thread active delay operation when , The thread will always be in function / be ready Stage , And because in my program ,main Thread has the highest priority , So my main Threads have been occupying system resources , Caused the illusion of system downtime . But if I was main Thread while(1) Insert... In the loop A delay procedure ,main The thread will enter Pending state , Give up system resources , So that other threads have a chance to be scheduled , Make the system run stably .
边栏推荐
- SQL time injection
- Reno7 60W super flash charging architecture
- ESP8266通过Arduino IDE连接Onenet云平台(MQTT)
- Internet protocol details
- 几个关于指针的声明【C语言】
- Linux yum安装MySQL
- [Bluebridge cup 2020 preliminary] horizontal segmentation
- Machine learning -- linear regression (sklearn)
- Pytorch实现简单线性回归Demo
- There are three iPhone se 2022 models in the Eurasian Economic Commission database
猜你喜欢
随机推荐
R & D thinking 01 ----- classic of embedded intelligent product development process
【presto】presto 参数配置优化
分布式节点免密登录
【flink】flink学习
Pytoch Foundation
TypeScript
Yarn installation and use
Apprentissage automatique - - régression linéaire (sklearn)
Funny cartoon: Programmer's logic
RT-Thread 线程的时间片轮询调度
OSPF message details - LSA overview
Oppo vooc fast charging circuit and protocol
Connexion sans mot de passe du noeud distribué
Detailed explanation of nodejs
Keyword inline (inline function) usage analysis [C language]
Mysql database interview questions
[NPUCTF2020]ReadlezPHP
arduino获取数组的长度
使用LinkedHashMap实现一个LRU算法的缓存
Mysql的索引实现之B树和B+树