赞
踩
#include <stdio.h> #include <string.h> #include <unistd.h> #include “ohos_init.h” #include “cmsis_os2.h” void thread1_func(void) //线程1执行的功能函数 { while(1) { printf(“hello\n”); sleep(1); } } void thread2_func(void) //线程2执行的功能函数 { while(1) { printf(“harmony\n”); sleep(1); } } static void threadTest(void) { osThreadAttr_t attr;//定义线程属性结构体变量 attr.name = “thread1”;//线程名称设置 attr.attr_bits = 0U;//线程属性位设置 //线程控制块内存和大小配置 attr.cb_mem = NULL; attr.cb_size = 0U; //线程堆栈内存和大小配置 attr.stack_mem = NULL; attr.stack_size = 1024; //创建线程,并且判断是否创建成功 if(osThreadNew((osThreadFunc_t)thread1_func, NULL, &attr) == NULL) { printf(“failed to create thread1\n”); } //创建线程2,修改线程名称,可以共用同一个线程对象的其他属性 attr.name = “thread2”; if(osThreadNew((osThreadFunc_t)thread2_func, NULL, &attr) == NULL) { printf(“failed to create thread2\n”); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。