#include "msg_queue.h"
#include "demo_thread.h"
int main()
{
int wait_flag;
msg_ptr p;
HANDLE h_app_thread1,h_app_thread2,h_kernel_thread;
DWORD app_thread1_id,app_thread2_id,kernel_thread_id;
msg_queue app_queue,kernel_queue;
printf("start!\n");
printf("initial app msg queue...\n");
init_msg_queue(&app_queue);
printf("initial kernel msg queue...\n");
init_msg_queue(&kernel_queue);
//create threads
printf("start threads...\n");
h_app_thread1=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)app_thread1_func,&app_queue,0,&app_thread1_id);
h_app_thread2=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)app_thread2_func,&app_queue,0,&app_thread2_id);
h_kernel_thread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)kernel_thread_func,&kernel_queue,0,&kernel_thread_id);
printf("thread1_id:%ld,thread2_id:%ld,thread3_id:%ld\n",app_thread1_id,app_thread2_id,kernel_thread_id);
app_msg_mutex=CreateMutex(NULL,FALSE,NULL);
while(1)
{
Sleep(1000);wait_flag=0;
while(is_empty_msg_queue(app_queue) && is_empty_msg_queue(kernel_queue)){
if(!wait_flag){ printf("waiting...");wait_flag=1;}
else printf(".");
Sleep(100);
}
if(msg_dequeue(&app_queue,&p)){
printf("\napp_dequeue:%s\n",p->msg_dat);
free(p);
}
if(msg_dequeue(&kernel_queue,&p)){
printf("kernel_dequeue:%s\n",p->msg_dat);
free(p);
}
}
CloseHandle(app_msg_mutex);
TerminateThread(h_app_thread1,0);
TerminateThread(h_app_thread2,0);
TerminateThread(h_kernel_thread,0);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
msg_queue.rar (23个子文件)
msg_queue
msg_queue.h 541B
demo_thread.cpp 913B
demo_thread.h 250B
msg_queue.cpp 865B
msg_queue.dsw 541B
demo_main.cpp 2KB
msg_queue.opt 120KB
msg_queue.plg 252B
Debug
msg_queue.sbr 0B
msg_queue.ilk 208KB
msg_queue.pch 222KB
demo_thread.obj 13KB
msg_queue.obj 5KB
msg_queue.bsc 3.1MB
vc60.idb 145KB
demo_main.obj 14KB
demo_thread.sbr 0B
demo_main.sbr 0B
vc60.pdb 76KB
msg_queue.exe 172KB
msg_queue.pdb 449KB
msg_queue.ncb 57KB
msg_queue.dsp 4KB
共 23 条
- 1
zyl112358
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页