RTT例程練習 1 5 優先順序相同執行緒輪轉排程

2022-03-15 17:42:37 字數 1047 閱讀 6443

之前說過,相同優先順序的執行緒,在自己的時間片用光之後,會被剝奪排程器,讓給同優先順序的其他執行緒。

程式:

#include static struct rt_thread thread1;

static struct rt_thread thread2;

static char thread1_stack[512];

static char thread2_stack[512];

//static rt_uint32_t t1_count = 0;

//static rt_uint32_t t2_count = 0;

static void thread1_entry(void* parameter)

}static void thread2_entry(void* parameter)

}/*@}*/

輸出結果:

thread1:

this is

ademo

thread2:

this is

ademo

thread2:

this is

ademo

thread2:

this is

ademo

thread2:

this is

ademo

thread2:

this is

ademo

thread2:

this isthread11111111111111111111111111:

this is

ademo

ademo

thread2:

this is

ademo

thread2:

this is

ademo

thread2:

this is

ademo

thread2:

this is

ademo

可以看到thread2 的時間片用光,插入了thread1 的列印內容。

RTT例程練習 1 5 優先順序相同執行緒輪轉排程

之前說過,相同優先順序的執行緒,在自己的時間片用光之後,會被剝奪排程器,讓給同優先順序的其他執行緒。程式 include static struct rt thread thread1 static struct rt thread thread2 static char thread1 stack...

RTT例程練習 1 4 執行緒優先順序搶占

rtt 是搶占式的rtos,高優先順序的執行緒會先執行。這個例程顯示了是如何搶占的。解釋我懶得寫了,下面這段來自官網論壇 因為更高的優先順序,thread1率先得到執行,隨後它呼叫延時,時間為3個系統tick,於是thread2得到執行。可以從列印結果中發現乙個規律,在第一次thread2了列印兩次...

1 5 實現優先順序佇列

想要實現乙個佇列,能夠以給定的優先順序來對準榮盛排序,而且每次pop操作時候都會返回優先順序最高的那個元素 使用heapq模組來實現乙個簡單的優先順序佇列 import heapq class priorityqueue def init self self.queue self.index 0 d...