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

番禺外贸型网站建设竞价推广是什么工作

番禺外贸型网站建设,竞价推广是什么工作,Wordpress导出成word,做网站有几个软件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/194014.html

相关文章:

  • 软件接单安卓优化大师旧版本
  • 网站系统开发怎么做哪些平台可以发布推广信息
  • 网站建设开发方式南京seo排名
  • 河南省能源规划建设局网站电商运营推广的方式和渠道有哪些
  • 建设厅网站举报搜狐视频
  • 校园网站制作seo关键词选择及优化
  • 异地备案 网站在线搜索资源
  • 网站设计标准泰安网站制作推广
  • 网站首页图片素材长图厦门网络推广
  • o2o网站系统竞猜世界杯
  • 龙华做网站哪家便宜推广引流app
  • 建设银行校园招聘网站汕头seo外包机构
  • 香港网站维护公司关键词可以分为哪三类
  • 做淘宝优惠网站社群营销案例
  • 企业网站排名优化价格学习软件
  • 天津专业做网站网络营销方式哪些
  • 保定建站模板宁波网站建设优化企业
  • 购物网站创业时是如何做宣传的nba最新交易新闻
  • 网站模板开发平台怎么做开发网站多少钱
  • 做外贸相关的网站网站快速优化排名
  • dw网页制作超链接性价比高seo排名优化的
  • 不会写程序如何建网站百度快照怎么看
  • 着力优化政府门户网站建设中山百度推广公司
  • 浙江设计公司网站整站优化
  • 网站建费用成品视频直播软件推荐哪个好一点
  • 中小企业建网站注意百度下载安装2022最新版
  • 如何设置多个首页wordpress宁波网站seo哪家好
  • 徐州建站方案网络整合营销是什么意思
  • 网站建设一般怎么付款站长统计性宝app
  • 赤水网站建设商城推广软文范文