操作系统课程设计——假脱机打印程序与虚拟设备

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

//该文件所含代码是课设需要学生自己写的代码和补充的代码,包含部分需要修改的课程设计指导书中的代码,不包含不需修改的代码//1.主程序intmain(intargc,char*argv[]){charselect;//按如下顺序创建互斥体、信号和线程h_print=CreateSemaphore(NULL,0,1,NULL);h_sendthread_to_mainthread=CreateSemaphore(NULL,0,1,NULL);h_spoolthread_to_mainthread=CreateSemaphore(NULL,0,1,NULL);h_semaphore_spool=CreateSemaphore(NULL,0,1,NULL);h_send=CreateThread(NULL,0,sendthread,NULL,0,NULL);h_spool_thread=CreateThread(NULL,0,spool_thread,NULL,0,NULL);h_spool_mutex=CreateMutex(NULL,FALSE,NULL);h_screen_mutex=CreateMutex(NULL,FALSE,NULL);h_spool_full=CreateSemaphore(NULL,0,MAX_SPOOL,NULL);h_spool_empty=CreateSemaphore(NULL,MAX_SPOOL,MAX_SPOOL,NULL);WaitForSingleObject(h_screen_mutex,INFINITE);while(1){printf(|-----------------------------------|\n);printf(|1:sendaprintrequest|\n);printf(|2:listspoolqueue|\n);printf(|3:printafileinspool|\n);printf(|4:exit|\n);printf(|-----------------------------------|\n);printf(selectafunction(1~4):);do{select=(char)getch();}while(select!='1'&&select!='2'&&select!='3'&&select!='4');system(cls);ReleaseMutex(h_screen_mutex);switch(select){case'1':ReleaseSemaphore(h_print,1,NULL);WaitForSingleObject(h_sendthread_to_mainthread,INFINITE);break;case'2':list_spool_queue();break;case'3':ReleaseSemaphore(h_semaphore_spool,1,NULL);WaitForSingleObject(h_spoolthread_to_mainthread,INFINITE);break;case'4':return0;}WaitForSingleObject(h_screen_mutex,INFINITE);printf(\nPressanykeytoreturntomainmenu.);getch();system(cls);ReleaseMutex(h_screen_mutex);}return0;}//2.打印线程函数DWORDWINAPIspool_thread(LPVOIDlpParameter){while(1){WaitForSingleObject(h_semaphore_spool,INFINITE);WaitForSingleObject(h_spool_mutex,INFINITE);WaitForSingleObject(h_screen_mutex,INFINITE);if(WaitForSingleObject(h_spool_full,10)==WAIT_TIMEOUT){printf(打印队列空!);}else{spool_buffer.spool_count--;printf(printafileinspool:\nfilename:%s\n,spool_buffer.spool_queue[spool_buffer.spool_out].file_name);strcpy(spool_buffer.spool_queue[spool_buffer.spool_out].file_name,);spool_buffer.spool_queue[spool_buffer.spool_out].file_size=0;spool_buffer.spool_out=(spool_buffer.spool_out+1)%MAX_SPOOL;}ReleaseMutex(h_screen_mutex);ReleaseMutex(h_spool_mutex);ReleaseSemaphore(h_spool_empty,1,NULL);ReleaseSemaphore(h_spoolthread_to_mainthread,1,NULL);}return0;}//主界面//执行1命令后//执行2命令后//执行3命令后//再次执行3命令后

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功