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

网站代付系统怎么做济南谷歌推广

网站代付系统怎么做,济南谷歌推广,下载天眼查企业查询官网,上海包装设计公司CMSIS 2.0 接口中的 Semaphore(信号量)是用于嵌入式系统中多线程或中断服务例程(ISR)之间同步和共享资源保护的重要机制。Semaphore 是一种用于控制对多个共享资源访问的同步机制。它可以被看作是一个计数器,用于跟踪可…

CMSIS 2.0 接口中的 Semaphore(信号量)是用于嵌入式系统中多线程或中断服务例程(ISR)之间同步和共享资源保护的重要机制。Semaphore 是一种用于控制对多个共享资源访问的同步机制。它可以被看作是一个计数器,用于跟踪可用资源的数量。

特性

计数信号量:Semaphore 可以作为计数信号量使用,管理多个相同类型的资源。例如,如果有多个 DMA 通道,可以使用 Semaphore 来限制同时访问这些通道的数量。

生产者/消费者信号量:Semaphore 也可以用于实现生产者和消费者之间的同步,确保在消费者准备好之前,生产者不会覆盖数据。

Semaphore在并发编程中确实可以作为一种锁来使用,用于控制多个线程对共享资源的访问。首先,你需要确定在任意时刻能够同时访问共享资源的最大线程数,并将这个数作为初始值来创建一个Semaphore对象。这个初始值通常表示许可的数量,每个许可允许一个线程访问共享资源。当线程想要访问共享资源时,它应该首先调用Semaphore对象的osSemaphoreAcquire()方法。这个方法会尝试从Semaphore中获取一个许可。如果Semaphore中有可用的许可(即计数器的值大于0),那么线程会立即获取一个许可并继续执行。如果没有可用的许可(即计数器的值为0),那么线程将被阻塞,直到有可用的许可。一旦线程成功获取到许可,它就可以安全地访问共享资源了。在访问期间,线程可以执行任何需要的操作。当线程完成对共享资源的访问后,它应该调用Semaphore对象的osSemaphoreRelease()方法来释放之前获取的许可。这个方法会将Semaphore的计数器加1,表示有一个新的许可可用。其他等待的线程(如果有的话)现在可能会获取到这个许可并继续执行。

Semaphore API

API名称

说明

osSemaphoreNew

创建并初始化一个信号量

osSemaphoreGetName

获取一个信号量的名字

osSemaphoreAcquire

获取一个信号量的令牌,若获取不到,则会超时返回

osSemaphoreRelease

释放一个信号量的令牌,但是令牌的数量不超过初始定义的的令牌数

osSemaphoreGetCount

获取当前的信号量令牌数

osSemaphoreDelete

删除一个信号量

代码编写

修改D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. import("//build/lite/config/component/lite_component.gni")lite_component("demo") {features = [#"base_00_helloworld:base_helloworld_example",#"base_01_led:base_led_example",#"base_02_loopkey:base_loopkey_example",#"base_03_irqkey:base_irqkey_example",#"base_04_adc:base_adc_example",#"base_05_pwm:base_pwm_example",#"base_06_ssd1306:base_ssd1306_example",#"kernel_01_task:kernel_task_example",#"kernel_02_timer:kernel_timer_example",#"kernel_03_event:kernel_event_example",#"kernel_04_mutex:kernel_mutex_example","kernel_05_semaphore_as_mutex:kernel_semaphore_as_mutex_example",]
}

创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\kernel_05_semaphore_as_mutex文件夹

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\kernel_05_semaphore_as_mutex\kernel_semaphore_as_mutex_example.c文件D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\kernel_05_semaphore_as_mutex\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. static_library("kernel_semaphore_as_mutex_example") {sources = ["kernel_semaphore_as_mutex_example.c"]include_dirs = ["//utils/native/lite/include","//kernel/liteos_m/kal/cmsis",]
}
/** Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**    http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/#include <stdio.h>
#include <unistd.h>#include "ohos_init.h"
#include "cmsis_os2.h"osThreadId_t Task1_ID;        //  任务1 ID
osThreadId_t Task2_ID;        //  任务2 ID
osSemaphoreId_t Semaphore_ID; // 信号量ID
uint8_t buff[20] = {0};       // 定义一个共享资源
#define TASK_STACK_SIZE 1024
#define TASK_DELAY_TIME 1 // s/*** @description: 任务1* @param {*}* @return {*}*/
void Task1(void)
{int i = 0;while (1) {printf("[info] enter Task 1.......\n");osSemaphoreAcquire(Semaphore_ID, osWaitForever); // 请求信号量 -1// 操作共享数据 写数据printf("[info] write Buff Data: \n");for (i = 0; i < sizeof(buff); i++) {buff[i] = i;}printf("\n");osSemaphoreRelease(Semaphore_ID); // 释放信号量 +1sleep(TASK_DELAY_TIME);}
}
/*** @description: 任务2* @param {*}* @return {*}*/
void Task2(void)
{int i = 0;while (1) {printf("enter Task 2.......\n");osSemaphoreAcquire(Semaphore_ID, osWaitForever); // 请求信号量 -1// 操作共享数据 读数据printf("[info] read Buff Data: \n");for (i = 0; i < sizeof(buff); i++) {printf("%d \n", buff[i]);}printf("\n");osSemaphoreRelease(Semaphore_ID); // 释放信号量 +1sleep(TASK_DELAY_TIME);}
}
/*** @description: 初始化并创建任务* @param {*}* @return {*}*/
static void kernel_mutex_semaphore_example(void)
{printf("Enter kernel_mutex_semaphore_example()!\n");// 创建信号量Semaphore_ID = osSemaphoreNew(1, 1, NULL); // 参数: 最大计数值,初始计数值,参数配置if (Semaphore_ID != NULL) {printf("ID = %d, Create Semaphore_ID is OK!\n", Semaphore_ID);}osThreadAttr_t taskOptions;taskOptions.name = "Task1";              // 任务的名字taskOptions.attr_bits = 0;               // 属性位taskOptions.cb_mem = NULL;               // 堆空间地址taskOptions.cb_size = 0;                 // 堆空间大小taskOptions.stack_mem = NULL;            // 栈空间地址taskOptions.stack_size = TASK_STACK_SIZE;           // 栈空间大小 单位:字节taskOptions.priority = osPriorityNormal; // 任务的优先级Task1_ID = osThreadNew((osThreadFunc_t)Task1, NULL, &taskOptions); // 创建任务1if (Task1_ID != NULL) {printf("ID = %d, Create Task1_ID is OK!\n", Task1_ID);}taskOptions.name = "Task2";                                        // 任务的名字taskOptions.priority = osPriorityNormal;                           // 任务的优先级Task2_ID = osThreadNew((osThreadFunc_t)Task2, NULL, &taskOptions); // 创建任务2if (Task2_ID != NULL) {printf("ID = %d, Create Task2_ID is OK!\n", Task2_ID);}
}
SYS_RUN(kernel_mutex_semaphore_example);

使用build,编译成功后,使用upload进行烧录。

http://www.yidumall.com/news/103275.html

相关文章:

  • 网站上的vR场景贴图怎么做的站长工具查询域名信息
  • 网站开发框架拓扑国际新闻今天最新消息
  • 做多级分销的网站100条经典广告语
  • 做响应网站的素材网站有哪些seo推广是什么意思
  • 只做一页的网站多少钱百度小说搜索热度排行榜
  • 网站各个功能模块网络推广员
  • 上海公司查询网站网站权重查询接口
  • 有哪些网站做外贸的百度账号人工客服
  • 开发一个微信小程序多少费用seo站长工具推广平台
  • 上海做网站需要多少钱微软bing搜索引擎
  • 亚洲人成网站在线播放18宜昌今日头条新闻
  • 那个网站都有做莱的图片网站关键词排名查询工具
  • wordpress 4.0模板seo整站优化什么价格
  • 网站建设jutuibao迅雷磁力链bt磁力天堂下载
  • 长沙专业网站制作设计镇江网站seo
  • 向wordpress发帖插件西安网络推广优化培训
  • 深圳建筑人才网招聘信息seo蜘蛛屯
  • 网站设计与制作培训班社群营销的十大步骤
  • 手机游戏制作软件appseo排名计费系统
  • 个人网站建设方案买链接官网
  • 中国住房和城乡建设部百度seo怎么优化
  • 老网站用新域名军事新闻最新
  • 委托广告公司做的网站违法了优化搜索曝光次数的方法
  • 广药网站建设试卷深圳全网推广效果如何
  • 专业做设计的网站seo营销推广全程实例
  • 保定官网优化技巧合肥网络公司seo
  • 网站被做301技术培训机构
  • 石家庄 外贸网站建设公司西安自助建站
  • 网站建设乌鲁木齐百度关键词排名推广话术
  • 集团网站设计公司电子商务营销方法