RT-Thread (task) Processing [RT-thread learning notes 2], rt-Thread learning notes

Source: Internet
Author: User

RT-Thread (task) Processing [RT-thread learning notes 2], rt-Thread learning notes

RT-Thread uses the Thread concept instead of the task. The two are similar. Here I understand his thread as a task.

1, Task Processing:

Dynamic Task APIs

Create task: rt_thread_create function. After a task is created, the rt_thread_t type task ID is returned.

Start the task after creation: rt_thread_startup

Delete task: rt_thread_delete

Task latency function: When rt_thread_delay is delayed, the task is in the suspend state.

The task running status can be viewed in the finish module on the computer terminal.

2. Dynamic and Static creation threads

RT-Thread supports static and dynamic definitions. For example, rt_thread_init corresponds to the static definition mode, and rt_thread_create corresponds to the dynamic definition mode.

  • UseStaticWhen defining a thread, you must first define a static thread control block, define the stack space, and then call rt_thread_init to complete thread initialization. In this way, the memory occupied by the thread control block and stack will be placed in the RW segment, which has been determined during compilation. It cannot be dynamically allocated, so it cannot be released, instead, you can only use the rt_thread_detach function to remove the thread control block from the object manager.
  • UseDynamicWhen rt_thread_create is defined, RT-Thread dynamically applies for the Thread control block and stack space. During compilation, the compiler will not perceive this blank space. RT-Thread will apply for allocation of this memory space from the System Heap only when the program is running, when you do not need to use this thread, call the rt_thread_delete function to release the applied memory space to the memory heap.

The two methods have their own advantages and disadvantages. The static definition method occupies RW/ZI space, but does not need to dynamically allocate memory. The running timeliness is high and the real-time performance is good. The dynamic mode does not occupy extra RW/ZI space, but takes up a small amount of space. However, the memory needs to be dynamically allocated during running, and the efficiency is not high in the static mode.

Static creation thread code:

Creation thread:rt_thread_init

Startup thread:rt_thread_startup

Thread disconnection:rt_thread_detach

// Static creation thread result = rt_thread_init (& thread1, // thread handle "static", // thread name rt_init_thread_entry, // thread entry function RT_NULL, // thread entry parameter & threadconsumer stack [0], // thread stack address sizeof (threadconsumer stack), // thread stack size 6, // thread priority 10); // thread time slice

Dynamic thread creation code:

Creation thread:rt_thread_create

Startup thread: rt_thread_startup

After the thread is started successfully, it can be scheduled and executed by the OS when the OS scheduling starts.

tid = rt_thread_create("init",        rt_init_thread_entry, RT_NULL,        2048, 10, 5);    if (tid != RT_NULL)        rt_thread_startup(tid);

Space usage comparison

Dynamically created threads. Space is released after deletion.

The static creation thread will not release space after detach


Domestic RTOS, such as Dujiangyan real-time operating system? RT-Thread? And so on. Are there other things besides these two? Is there a company dedicated to RTOS?

RT-Thread RTOS
This is an open-source real-time operating system developed by RT-Thread studio in China. RT-Thread is a real-time kernel (fully preemptible priority scheduling, scheduler time complexity O (1), but in the development process, the RT-Thread real-time operating system is fully supported by embedded development engineers from all over the country and has become a complete and full-featured operating system: file system, network protocol stack, graphical interface components... Only you can't think of it, but you can't do it: RT-Thread is a platform. You can bring your ideas together. The RT-Thread developers are at your side in the big community of the small platform.

How to Use the rt-thread Programming Language

I think there are two possibilities:
1. The first byte address of the space where the struct content is stored
2. Each member of the struct has its own address. These addresses are placed in a contiguous memory, and the pointer of the struct stores the first byte address of this contiguous memory.
Actually, it is not so important for the specific content in this struct pointer. You only need to know how to use this pointer.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.