⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testforlinux.bk

📁 用linux操作系统接口封装的兼容os20的操作系统接口
💻 BK
字号:
#include "osforlinux.h"void *thread1(void *ParamP_p);void *thread2(void *ParamP_p);void *thread3(void *ParamP_p);void *thread4(void *junk);int i;task_t *t_a,*t_b,*t_c;osforlinux_mq_t *g_mq;		void test_osforlinux(){	int _err=0;	int *msg=NULL;		_err=osforlinux_task_create((void*)thread4,NULL,NULL,0,NULL,NULL,&t_a,NULL,1,"thread4",0);#if 0	g_mq = osforlinux_mq_create(sizeof(int),10);		_err=osforlinux_task_create((void*)thread1,NULL,NULL,0,NULL,NULL,&t_a,NULL,10,"thread1",0);	if(_err != 0)	{		printf("create thread1 Error ! \n");		return;	}	_err=osforlinux_task_create((void*)thread2,NULL,NULL,0,NULL,NULL,&t_b,NULL,10,"thread2",0);	if(_err != 0)	{		printf("create thread2 Error ! \n");		return;	}	printf("t_a:%d t_b:%d\n",*t_a,*t_b);	_err=osforlinux_task_create((void*)thread3,NULL,NULL,0,NULL,NULL,&t_c,NULL,10,"thread3",0);	sleep(2);	{		int _index;		for(_index=0;_index<2;_index++)		{			msg = (int *)osforlinux_mq_claim(g_mq);			*msg=989+_index;			printf("send msg: %d !\n",*msg);			osforlinux_mq_send(g_mq,msg);		}		}	sleep(5);	if(osforlinux_task_delete(t_a,NULL,NULL,NULL) == 0)		printf("delete tid1 !\n");	else		printf("faild delete tid1 !\n");				if(osforlinux_task_delete(t_b,NULL,NULL,NULL)==0)		printf("delete tid2 !\n");	else		printf("faild delete tid2 !\n");		if(osforlinux_task_delete(t_c,NULL,NULL,NULL) == 0)		printf("delete tid3 !\n");	else		printf("faild delete tid3 !\n");	sleep(2);	printf("exit test_osforlinux !\n");#endif}void *thread1(void *junk){	int ii=0;    for(i=1;i<=9;i++)    {        if(i%3==0)		{			printf("thread1:%d pthread_cond_signal !\n",i);			osforlinux_task_resume(t_b);//			osforlinux_task_resume(t_c);		}        else		{            printf("thread1:%d\n",i);		}        printf("thread1: Unlock Mutex\n");             sleep(1);    }}void *thread2(void *junk){       while(i<9)       {			 printf("thread2:%d pthread_cond_wait !\n",i);//			 if(i%3!=0)				osforlinux_task_suspendself(t_c);             printf("thread2:%d ",i);             printf("thread2: Ulock Mutex\n");             sleep(1);       }}void *thread3(void *junk){       while(i<9)       {			 printf("thread3:%d pthread_cond_wait !\n",i);			 if(i%3!=0)/*			 {				int *msg;//				osforlinux_task_suspendself(NULL); 				printf("receive msg !\n");				msg = osforlinux_mq_receive(g_mq);				printf("thread3: msg=%d \n",*msg);				osforlinux_mq_release(g_mq,msg);			 }*/             printf("thread3:%d ",i);             printf("thread3: Ulock Mutex\n");             sleep(1);       }}void *thread4(void *junk){       while(1)       {			printf("thread4:running !\n",i);            sleep(5);       }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -