• 大小: 6.54MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2022-05-10
  • 语言: 其他
  • 标签:

资源简介

操作系统实验,实现缓冲区的互斥访问,利用临界区实现

资源截图

代码片段和文件信息

// arrythread.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include “windows.h“
#include “process.h“
#include 

CRITICAL_SECTION g_cs;
char g_arry[10];

UINT threadproc10(LPVOID pParam){
//EnterCriticalSection(&g_cs);
for (int i=0;i<10;i++){
g_arry[i]=‘a‘;
printf(“a-%d\n“i);
Sleep(1);
if (i%2==0)
{
Sleep(2);
}
}
//LeaveCriticalSection(&g_cs);
return 0;
}

UINT threadproc11(LPVOID pParam){
//EnterCriticalSection(&g_cs);
for (int i=0;i<10;i++)
{
g_arry[i]=‘b‘;
printf(“b-%d\n“i);
Sleep(1);
if (i%3==0)
{
Sleep(3);
}
}
//LeaveCriticalSection(&g_cs);
return 0;
}

int _tmain(int argc _TCHAR* argv[])
{
InitializeCriticalSection(&g_cs);

HANDLE hthread1=CreateThread(NULL0(LPTHREAD_START_ROUTINE)threadproc10NULL0NULL);
HANDLE hthread2=CreateThread(NULL0(LPTHREAD_START_ROUTINE)threadproc11NULL0NULL);
WaitForSingleobject(hthread1INFINITE);
CloseHandle(hthread1);
WaitForSingleobject(hthread2INFINITE);
//CloseHandle(hthread1);
CloseHandle(hthread2);

Sleep(300);
for (int i=0;i<10;i++)
{
printf(“%c\n“g_arry[i]);
}
Sleep(10000);
//CString sresult=CString(g_arry);
//AfxMessageBox(sresult);
return 0;
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1268  2011-10-31 19:02  arrythread\arrythread\arrythread.cpp

     文件       4372  2011-10-20 08:42  arrythread\arrythread\arrythread.vcxproj

     文件       1314  2011-10-20 08:42  arrythread\arrythread\arrythread.vcxproj.filters

     文件        143  2011-10-20 08:42  arrythread\arrythread\arrythread.vcxproj.user

     文件        406  2011-10-20 08:54  arrythread\arrythread\Debug\arrythread.exe.embed.manifest

     文件        472  2011-10-20 08:54  arrythread\arrythread\Debug\arrythread.exe.embed.manifest.res

     文件        381  2011-10-31 19:01  arrythread\arrythread\Debug\arrythread.exe.intermediate.manifest

     文件         56  2011-10-31 19:01  arrythread\arrythread\Debug\arrythread.lastbuildstate

     文件       2276  2011-10-31 19:01  arrythread\arrythread\Debug\arrythread.log

     文件      54483  2011-10-31 19:01  arrythread\arrythread\Debug\arrythread.obj

     文件    1179648  2011-10-20 08:49  arrythread\arrythread\Debug\arrythread.pch

     文件        210  2011-10-20 08:54  arrythread\arrythread\Debug\arrythread_manifest.rc

     文件       1482  2011-10-31 19:01  arrythread\arrythread\Debug\cl.command.1.tlog

     文件      22900  2011-10-31 19:01  arrythread\arrythread\Debug\CL.read.1.tlog

     文件        814  2011-10-31 19:01  arrythread\arrythread\Debug\CL.write.1.tlog

     文件          2  2011-10-31 19:01  arrythread\arrythread\Debug\link-cvtres.read.1.tlog

     文件          2  2011-10-31 19:01  arrythread\arrythread\Debug\link-cvtres.write.1.tlog

     文件          2  2011-10-31 19:01  arrythread\arrythread\Debug\link.2940-cvtres.read.1.tlog

     文件          2  2011-10-31 19:01  arrythread\arrythread\Debug\link.2940-cvtres.write.1.tlog

     文件          2  2011-10-31 19:01  arrythread\arrythread\Debug\link.2940.read.1.tlog

     文件          2  2011-10-31 19:01  arrythread\arrythread\Debug\link.2940.write.1.tlog

     文件       1656  2011-10-31 19:01  arrythread\arrythread\Debug\link.command.1.tlog

     文件       3256  2011-10-31 19:01  arrythread\arrythread\Debug\link.read.1.tlog

     文件        876  2011-10-31 19:01  arrythread\arrythread\Debug\link.write.1.tlog

     文件        400  2011-10-31 19:01  arrythread\arrythread\Debug\mt.command.1.tlog

     文件        326  2011-10-31 19:01  arrythread\arrythread\Debug\mt.read.1.tlog

     文件        326  2011-10-31 19:01  arrythread\arrythread\Debug\mt.write.1.tlog

     文件        554  2011-10-20 08:54  arrythread\arrythread\Debug\rc.command.1.tlog

     文件        298  2011-10-20 08:54  arrythread\arrythread\Debug\rc.read.1.tlog

     文件        306  2011-10-20 08:54  arrythread\arrythread\Debug\rc.write.1.tlog

............此处省略22个文件信息

评论

共有 条评论

相关资源