資源簡介
操作系統生產者——消費者模擬程序
兩個線程里創建獨立的定時器

代碼片段和文件信息
#include?“P_C.h“
#include?
#include?
#include?
#pragma?comment(lib?“P_C_Dll.lib“)
int?main(int?argc?char?**?argv)
{
ContainerType?c?=?C_LOOP_QUEUE;
UINT?producerTimer?=?500;
UINT?consumerTimer?=?1000;
int?opr?res;
if(argc?>=?2)
{
if(strlen(argv[1])?>=?4)
{
if(argv[1][0]?==?‘/‘?&&?argv[1][1]?==?‘c‘?&&?argv[1][2]?==?‘:‘)
{
if(argv[1][3]?==?‘s‘)
c?=?C_STACK;
else?if(argv[1][3]?==?‘q‘)
c?=?C_LOOP_QUEUE;
}
}
}
Initialize(c?producerTimer?consumerTimer);
ProducerStart();
ConsumerStart();
printf(“??????????????????????生產者——消費者模擬系統\n“);
printf(“----------------------------------------------------------------------\n“);
printf(“???Producer???????????????????????????????Consumer\n“);
printf(“----------------------------------------------------------------------\n“);
ResumeAll();
while(1)
{
system(“pause?>?nul“);
SuspendAll();
printf(“----------------------------------------------------------------------\n“);
printf(“Select?an?operation(1?2?3):\n“);
printf(“\t1.?更改生產者速度\n\t2.?更改消費者速度\n\t3.?退出程序\n“);
do{
printf(“\n>“);
res?=?scanf(“%d“?&opr);
rewind(stdin);
}while(res?==?0?||?(opr?!=?1?&&?opr?!=?2?&&?opr?!=?3));
if(opr?==?1)
{
printf(“輸入生產者時間間隔(?>50?):\n“);
do{
printf(“\n>“);
res?=?scanf(“%d“?&producerTimer);
rewind(stdin);
}while(res?==?0?||?producerTimer?<=?50);
printf(“??????????????????????生產者——消費者模擬系統\n“);
printf(“----------------------------------------------------------------------\n“);
printf(“???Producer???????????????????????????????Consumer\n“);
printf(“----------------------------------------------------------------------\n“);
ResumeAll();
SetProducerTimer(producerTimer);
}
else?if(opr?==?2)
{
printf(“輸入消費者時間間隔(?>50?):\n“);
do{
printf(“\n>“);
res?=?scanf(“%d“?&consumerTimer);
rewind(stdin);
}while(res?==?0?||?consumerTimer?<=?50);
printf(“??????????????????????生產者——消費者模擬系統\n“);
printf(“----------------------------------------------------------------------\n“);
printf(“???Producer???????????????????????????????Consumer\n“);
printf(“----------------------------------------------------------------------\n“);
ResumeAll();
SetConsumerTimer(consumerTimer);
}
else?if(opr?==?3)
{
/*?ResumeAll();?*/
break;
}
}
StopAll();
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2545??2008-12-17?14:50??P_C\P_C.c
?????文件???????4326??2008-12-17?14:06??P_C\P_C.dsp
?????文件????????527??2008-12-17?13:06??P_C\P_C.h
?????文件?????208951??2008-12-17?14:15??P_C\P_C_Dll.dll
?????文件???????3302??2008-12-17?13:57??P_C\P_C_Dll.lib
?????文件????????162??2008-12-17?10:35??P_C_Dll\constant.h
?????文件???????1310??2008-12-17?12:40??P_C_Dll\loop_queue.c
?????文件????????610??2008-12-17?10:54??P_C_Dll\loop_queue.h
?????文件???????5278??2008-12-17?14:15??P_C_Dll\P_C_Dll.c
?????文件????????148??2008-12-17?13:06??P_C_Dll\P_C_Dll.def
?????文件???????4828??2008-12-17?13:57??P_C_Dll\P_C_Dll.dsp
?????文件????????560??2008-12-17?13:06??P_C_Dll\P_C_Dll.h
?????文件???????1035??2008-12-17?12:40??P_C_Dll\stack.c
?????文件????????495??2008-12-17?10:54??P_C_Dll\stack.h
?????文件????????165??2008-12-17?12:49??P_C_Dll\typedefine.h
?????文件????????734??2008-12-17?16:04??OS2008.dsw
?????目錄??????????0??2008-12-17?16:05??P_C
?????目錄??????????0??2008-12-17?16:05??P_C_Dll
-----------?---------??----------?-----??----
???????????????234976????????????????????18
- 上一篇:軟件項目開發的全套文檔——資料包15個DOC
- 下一篇:dtmf雙音多頻音頻分析軟件
評論
共有 條評論