当前位置: 首页 > wzjs >正文

物流网站的建设论文一万字wordpress 如何改中文字体

物流网站的建设论文一万字,wordpress 如何改中文字体,房屋装修效果图片欣赏,seo快速优化方法FreeRTOS 操作系统支持三种调度方式: 抢占式调度,时间片调度和合作式调度。 实际应用主要是抢占式调度和时间片调度,合作式调度用到的很少. 1,抢占式调度 每个任务都有不同的优先级, 任务会一直运行直到被高优先级任务抢占或者遇到…

FreeRTOS 操作系统支持三种调度方式: 抢占式调度,时间片调度和合作式调度。 实际应用主要是抢占式调度和时间片调度,合作式调度用到的很少.

1,抢占式调度
每个任务都有不同的优先级, 任务会一直运行直到被高优先级任务抢占或者遇到阻塞式的 API 函数,比如 vTaskDelay(延迟,事件标志等待,信号量等待)才会切换到其他任务。抢占式调度要掌握的最关键一点是: 每个任务都被分配了不同的优先级, 抢占式调度器会获得就绪列表中优先级最高的任务,并运行这个任务

FreeRTOS 操作系统是设置的数值越小任务优先级越低, 数值越大任务优先级越高,由于任务2的优先级高于任务1,因此任务2将首先运行。

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"#define TASK1_PRIORITY   (tskIDLE_PRIORITY + 1)
#define TASK2_PRIORITY   (tskIDLE_PRIORITY + 2)// 任务函数原型
void vTask1(void *pvParameters);
void vTask2(void *pvParameters);// 任务1函数
void vTask1(void *pvParameters) {const char *pcTaskName = (const char *)pvParameters;for (;;) {// 打印任务名printf("%s is running\n", pcTaskName);// 延时一段时间,模拟任务的工作负载vTaskDelay(pdMS_TO_TICKS(1000));}
}// 任务2函数
void vTask2(void *pvParameters) {const char *pcTaskName = (const char *)pvParameters;for (;;) {// 打印任务名printf("%s is running\n", pcTaskName);// 延时一段时间,模拟任务的工作负载vTaskDelay(pdMS_TO_TICKS(500));}
}int main(void) {// 创建任务xTaskCreate(vTask1, "Task 1", configMINIMAL_STACK_SIZE, "Task 1", TASK1_PRIORITY, NULL);xTaskCreate(vTask2, "Task 2", configMINIMAL_STACK_SIZE, "Task 2", TASK2_PRIORITY, NULL);// 启动调度器vTaskStartScheduler();// 如果调度器启动失败,将不会到达这里for (;;);
}

Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running

 抢占式调度算法实现。

#include <stdio.h>
#include <stdbool.h>#define NUM_TASKS 3typedef struct {int priority;bool isRunning;
} Task;void initTask(Task *task, int priority) {task->priority = priority;task->isRunning = false;
}void runTask(Task *task) {if (task->isRunning) {printf("Task with priority %d is running.\n", task->priority);}
}void scheduleTasks(Task *tasks, int numTasks) {int highestPriority = -1;int highestPriorityTaskIndex = -1;// Find the highest priority task that is ready to runfor (int i = 0; i < numTasks; ++i) {if (tasks[i].priority > highestPriority && !tasks[i].isRunning) {highestPriority = tasks[i].priority;highestPriorityTaskIndex = i;}}// Preempt lower priority tasksfor (int i = 0; i < numTasks; ++i) {tasks[i].isRunning = false;}// Run the highest priority taskif (highestPriorityTaskIndex != -1) {tasks[highestPriorityTaskIndex].isRunning = true;runTask(&tasks[highestPriorityTaskIndex]);}
}int main() {Task tasks[NUM_TASKS];initTask(&tasks[0], 1);initTask(&tasks[1], 2);initTask(&tasks[2], 3);// Initially, the highest priority task is runningtasks[2].isRunning = true;// Simulate schedulingprintf("Initial scheduling:\n");scheduleTasks(tasks, NUM_TASKS);// Now, a higher priority task becomes readyprintf("\nAfter a higher priority task becomes ready:\n");tasks[1].priority = 4; // Increase the priority of task 1scheduleTasks(tasks, NUM_TASKS);return 0;
}

 2, 时间片调度
每个任务都有相同的优先级, 任务会运行固定的时间片个数或者遇到阻塞式的 API 函数,比如
vTaskDelay, 才会执行同优先级任务之间的任务切换。

在 FreeRTOS 操作系统中只有同优先级任务才会使用时间片调度, 另外还需要用户在
FreeRTOSConfig.h 文件中使能宏定义:#define configUSE_TIME_SLICING 1

每个任务分配的时间片大小是 5 个系统时钟节拍。而在时间片轮询的过程中如果调用了阻塞式 API 函数, 调用函数时, 虽然 5 个系统时钟节拍的时间片大小还没有用完, 此时依然会通过时间片调度切换到下一个任务。

FreeRTOSConfig中:
configUSE_PREEMPTION=0关闭抢占,只有阻塞/挂起/运行的任务调用 taskYIELD()/ISR才会切换下文的任务

configUSE_TIME_SLICING=0关闭时间片,相同优先级的任务不会在tick间隔后切换。

#include "FreeRTOS.h"
#include "task.h"
#include<stdio.h>
#include "timers.h"void vApplicationMallocFailedHook() {while(1);
}void vApplicationStackOverflowHook(TaskHandle_t xTask, char * pcTaskName ) {while(1);
}#define TASK_PRIORITY 1
#define TASK_STACK_SIZE 256
#define TIME_SLICE_MS 1000// 任务句柄
TaskHandle_t taskHandles[2] = {NULL, NULL};// 时间片定时器回调函数
void vTimerCallback(TimerHandle_t xTimer) {// 交换两个任务的优先级,以实现时间片调度vTaskPrioritySet(taskHandles[0], TASK_PRIORITY + 1);vTaskPrioritySet(taskHandles[1], TASK_PRIORITY);
}// 任务函数
void vTaskFunction(void *pvParameters) {const char *pcTaskName = (const char *)pvParameters;UBaseType_t uxPriority;// 获取当前任务的优先级uxPriority = uxTaskPriorityGet(NULL);for (;;) {// 执行任务的工作printf("%s is running\n", pcTaskName);// 延时,模拟任务工作负载vTaskDelay(pdMS_TO_TICKS(TIME_SLICE_MS / 2));}
}int main(void) {// 创建两个任务xTaskCreate(vTaskFunction, "Task 1", TASK_STACK_SIZE, "Task 1", TASK_PRIORITY, &taskHandles[0]);xTaskCreate(vTaskFunction, "Task 2", TASK_STACK_SIZE, "Task 2", TASK_PRIORITY, &taskHandles[1]);// 创建一个定时器,用于周期性地切换任务优先级TimerHandle_t xTimer = xTimerCreate("Timer", pdMS_TO_TICKS(TIME_SLICE_MS), pdTRUE, (void *)0, vTimerCallback);// 启动定时器xTimerStart(xTimer, 0);// 启动调度器vTaskStartScheduler();// 如果调度器启动失败,将不会到达这里for (;;);
}

Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running

时间片c语言实现算法:

#include <stdio.h>
#include <stdbool.h>#define NUM_TASKS 2
#define TIME_SLICE 5typedef struct {int priority;int timeSliceCount;bool isRunning;
} Task;void initTask(Task *task, int priority) {task->priority = priority;task->timeSliceCount = 0;task->isRunning = false;
}void runTask(Task *task) {if (task->isRunning) {printf("Task with priority %d is running for time slice %d.\n", task->priority, task->timeSliceCount);}
}void scheduleTasks(Task *tasks, int numTasks) {static int currentTaskIndex = 0;// Stop the current tasktasks[currentTaskIndex].isRunning = false;tasks[currentTaskIndex].timeSliceCount = 0;// Move to the next taskcurrentTaskIndex = (currentTaskIndex + 1) % numTasks;// Start the next tasktasks[currentTaskIndex].isRunning = true;tasks[currentTaskIndex].timeSliceCount++;// Run the next taskrunTask(&tasks[currentTaskIndex]);
}int main() {Task tasks[NUM_TASKS];initTask(&tasks[0], 1);initTask(&tasks[1], 2);// Simulate round-robin schedulingprintf("Round-robin scheduling:\n");for (int i = 0; i < TIME_SLICE * NUM_TASKS; ++i) {scheduleTasks(tasks, NUM_TASKS);}return 0;
}

 

http://www.dtcms.com/wzjs/835214.html

相关文章:

  • 文化管 网站建设规划怎么做购物领券网站
  • 建设网站价钱建设银行登录网站
  • 外网网站无锡网站设计 众
  • 成都免费建网站公司旅游网站国内外研究现状
  • 点餐网站模板广告运营具体是做什么
  • 中英文微信网站建设专门设计网站的公司叫什么
  • 医院做网站的风格昆明信息港官网
  • 做网站 用哪种小型企业网站有哪些
  • 温州公司建设网站制作为什么建手机网站
  • dede网站301怎么做wordpress 替代
  • 鹤壁市建设局网站法国网站域名
  • 只做绿色食品的网站黄骅市天气预报最新
  • 怎么做网站生意thinkphp商城源码
  • 黑龙江省建设协会网站响应式企业展示型网站
  • 纪检监察信息网站建设电商网站模块有哪些
  • 做阿里巴巴网站店铺装修费用重庆网站建设的价格低
  • 网站建设基本情况网站管理员怎样管理员权限
  • 免费h5模板网站模板如何做好网站内容优化
  • 甘肃网站怎样备案怎么查看网站建设时间
  • 设置个网站要多少钱建设银行的网站你打不开
  • 替别人做网站管理员南宁模板做网站
  • 商务网站建设学期总结山西设计网站公司
  • 织梦系统做网站免费软件下载存在哪些风险
  • 服务器网站搭建教程搜索引擎优化的英文
  • 网站开发人员配置济南住房和城乡建设厅网站
  • 小县城做婚礼网站手机网站开发框架
  • 葛洲坝机电建设有限公司网站建设工程业绩补录 网站
  • 国外优秀论文网站网站微信认证
  • 青岛外贸网站推广外贸网站空间选择
  • 做网站公司排名效果图制作好学吗