Home > Backend Development > C++ > Day - Task Management (Operating System)

Day - Task Management (Operating System)

Patricia Arquette
Release: 2024-10-25 09:46:02
Original
812 people have browsed it

Dia - Gestão de Tarefas (Sistema Operacional)

These days I've been racking my brains to implement task management using context. Code here.

Like everything else in this project, this was another "task" of Professor Maziero's content.

About implementation:

A task management system was implemented using system contexts. It manages cooperative tasks by executing one task until explicitly moving to another.

task_t Structure: Represents a task, storing the execution context, an identifier (ID), and pointers to facilitate the construction of a doubly linked queue of tasks.

typedef struct task_t
{
  struct task_t *prev, *next; // ponteiros para usar em filas
  int id;                     // identificador da tarefa
  ucontext_t context;         // contexto armazenado da tarefa
  short status;               // pronta, rodando, suspensa, ...
  // ... (outros campos serão adicionados mais tarde)
} task_t;
Copy after login

Initialization: The ppos_init() function is called to configure the main context of the program. This prepares the system to manage multiple tasks.

Task creation: New tasks are created with task_init(), where you pass a function and arguments to be executed within the new task. These tasks are given a new context and stack, and the task ID is updated.

Context switching: The task_switch() function allows you to switch between tasks, exchanging the current context for that of a specified task.

Task termination: A task can terminate its execution and return to the main context with task_exit().

The above is the detailed content of Day - Task Management (Operating System). For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template