硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5136|回复: 0
收起左侧

[ThreadX全家桶] ThreadX支持的三种调度方式,时间片调度,抢占式调度和合作式调度

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115806
QQ
发表于 2021-5-11 09:35:38 | 显示全部楼层 |阅读模式

ThreadX手册中说的轮询调度方式就是合作式调度。

和其它RTOS区别的地方是ThreadX有个抢占阈值,可以关闭一些高优先级任务抢占低优先级任务的执行。

合作式调度方式:
  1. ULONG run_counter_1 = 0;
  2. ULONG run_counter_2 = 0;

  3. /* Example of two threads relinquishing control to
  4. each other in an infinite loop. Assume that
  5. both of these threads are ready and have the same
  6. priority. The run counters will always stay within one
  7. of each other. */

  8. VOID my_first_thread(ULONG thread_input)
  9. {
  10.     /* Endless loop of relinquish. */
  11.     while(1)
  12.     {
  13.         /* Increment the run counter. */
  14.         run_counter_1++;

  15.         /* Relinquish control to other thread. */
  16.         tx_thread_relinquish();
  17.     }
  18. }

  19. VOID my_second_thread(ULONG thread_input)
  20. {

  21.     /* Endless loop of relinquish. */
  22.     while(1)
  23.     {
  24.         /* Increment the run counter. */
  25.         run_counter_2++;

  26.         /* Relinquish control to other thread. */
  27.         tx_thread_relinquish();
  28.     }
  29. }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-20 08:31 , Processed in 0.197598 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表