Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Review 2: 增加任务间通信能力 #3

Open
LeeReindeer opened this issue Jan 23, 2022 · 1 comment
Open

Code Review 2: 增加任务间通信能力 #3

LeeReindeer opened this issue Jan 23, 2022 · 1 comment

Comments

@LeeReindeer
Copy link
Owner

LeeReindeer commented Jan 23, 2022

目前 ROS 提供的系统调用有如下四个:

  • ros_init(): 初始化系统时钟等
  • ros_create_task(*task, task_func, priority, stack, stack_size): 创建任务
  • ros_delay(ticks): 挂起任务一段时间,主动让出CPU
  • ros_schedule(): 任务调度,不必主动调用

功能十分有限和简洁简陋,之后会考虑提供更多系统调用,丰富任务间协同通信的能力:

  • ros_yield(x): 挂起任务并返回值,唤醒任意其他的任务
  • ros_join(*task): 等待其他任务结束
  • Channel: 任务间数据传递,类似 Go 中的 chan
  • Mutex: 互斥锁
@LeeReindeer LeeReindeer added the enhancement New feature or request label Jan 23, 2022
@LeeReindeer
Copy link
Owner Author

需要声明的是, ROS 实现的协程是 symmetric coroutine。因此任务不能嵌套调用(不存在调用者和被调用者的关系),任务都是在同一层级进行调度的。

在论文 Revisiting Coroutines 中又对其的明确定义:

A well-known classification of coroutines concerns the control-transfer operations that are provided and distinguishes the concepts of symmetric and asymmetric coroutines. Symmetric coroutine facilities provide a single control-transfer operation that allows coroutines to explicitly pass control between themselves. Asymmetric coroutine mechanisms (more commonly denoted as semi-symmetric or semi coroutines) provide two control-transfer operations: one for invoking a coroutine and one for suspending it, the latter returning control to the coroutine invoker. While symmetric coroutines operate at the same hierarchical level, an asymmetric coroutine can be regarded as subordinate to its caller, the relationship between them being somewhat similar to that between a called and a calling routine.

@LeeReindeer LeeReindeer changed the title Code Review 2 Code Review 2: 增加任务间通信能力 Jan 23, 2022
@LeeReindeer LeeReindeer pinned this issue Jan 23, 2022
@LeeReindeer LeeReindeer removed the enhancement New feature or request label Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant