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

Add cooperative task manager #82

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

vicitori
Copy link

@vicitori vicitori commented Dec 11, 2024

Cooperative task manager representation based on round-robin scheduling with priorities. CooperativeTask is a shell for Task (the general structure of the task for both cooperative and preemptive task manager) with fields id, status and priority.

API:
new --- create new task manager;
add_task --- create a task with default priority 0 and add it to the queue;
add_priority_task --- create a task with specified priority and add it to the queue;
find_task --- search and return for a task by its id;
put_to_sleep --- put the task to sleep by its id;
terminate_task --- put the task into the state of termination by its id. The task cannot be moved from this state to another one, it is deleted immediately using the delete_task function with private visibility;
start_task_task_manager --- starts task manager work;

Status of the task changes during it execution. It possible statuses: Ready, Running, Sleeping, Terminated

Comment on lines 84 to 100
let tasks = [
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
Vec::new(),
];
CooperativeTaskManager {
tasks,
next_task_id: 0,
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we begin with empty tasks array?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each vector is for tasks of a specific priority and all possible priorities are initialized at the start of the manager.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we create vector for exact priority, when task with such priority appears? Cause seems like we use unnecessary memory. It may be critical for devices with small memory such as esp32.

@IvanArkhipov1999
Copy link
Owner

Needs examples of new API usage

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

Successfully merging this pull request may close these issues.

2 participants