91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 273KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-06-07
  • 語言: 其他
  • 標簽: 讀者優先??

資源簡介

資源包括進程同步經典算法的讀寫者問題,讀者優先的全部代碼機器附帶的相關文件。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
using?namespace?std;

/*===============???class???signal???===============*/
class?signal?//信號量對象.
{
private:
????int?value;
????int?queue;?????//用int型數據模擬等待隊列.
public:
????signal();
????signal(int?n);
????int?P();?//檢查臨界資源
????int?V();?//釋放臨界資源
????int?Get_Value();
????int?Get_Queue();
};



const?int?MaxThread=20;

struct?ThreadInfo
{
????int?num;
????char?type;
????double?start;
????double?time;
}?thread_info[MaxThread];

void?Creat_Writer();????//添加一個寫者
void?Del_Writer();?????//刪除一個寫者
void?Creat_Reader();????//添加一個讀者
void?Reader_goon();?????//讀者進程運行函數
void?R_Wakeup();?????//喚醒等待讀者
void?Del_Reader();?????//刪除一個讀者
void?Show();?????//顯示運行狀態


HANDLE?hX;
HANDLE?hWsem;
HANDLE?thread[MaxThread];
int?readcount;
double?totaltime;

void?WRITEUNIT(int?iProcess)
{
????printf(“Thread?%d?begins?to?write.\n“iProcess);
????Sleep((DWORD)(thread_info[iProcess-1].time*1000));
????printf(“End?of?thread?%d??for?writing.\n“iProcess);

}

void?READUNIT(int?iProcess)
{
????printf(“Thread?%d?begins?to?read.\n“iProcess);
????Sleep((DWORD)(thread_info[iProcess-1].time*1000));
????printf(“End?of?thread?%d??for?reading.\n“iProcess);
}

DWORD???WINAPI???reader(LPVOID???lpVoid)
{
????int?iProcess???=???*(int*)lpVoid;
????Sleep((DWORD)(thread_info[iProcess-1].start*1000));
????DWORD?wait_for=WaitForSingleobject(hXINFINITE);
????printf(“Thread?%d?requres?reading.\n“iProcess);
????readcount++;
????if(readcount==1)WaitForSingleobject(hWsemINFINITE);
????ReleaseMutex(hX);
????READUNIT(iProcess);
????wait_for=WaitForSingleobject(hXINFINITE);
????readcount--;
????if(readcount==0)
????????ReleaseSemaphore(hWsem10);
????ReleaseMutex(hX);
????return?iProcess;
}

DWORD???WINAPI???writer(LPVOID???lpVoid)
{
????int?iProcess???=???*(int*)lpVoid;
????Sleep((DWORD)(thread_info[iProcess-1].start*1000));
????printf(“Thread?%d?requres?writing.\n“iProcess);
????DWORD?wait_for=WaitForSingleobject(hWsemINFINITE);
????WRITEUNIT(iProcess);
????ReleaseSemaphore(hWsem10);
????return?iProcess;
}

int?main()
{
????int?threadNum;
????int?threadcount;
????ifstream?file;

????hX=CreateMutex(NULL?FALSE?NULL);
????hWsem=CreateSemaphore(NULL11NULL);

????//???????????????????
????readcount=0;
????threadcount=0;
????totaltime=0;
????file.open(“thread.dat“ios::in);
????if(file==0)
????{
????????printf(“File?Open?Error.\n“);
????????return?0;
????}
????while(file>>threadNum)
????{
????????thread_info[threadNum-1].num=threadNum;
????????file>>thread_info[threadNum-1].type;
????????file>>thread_info[threadNum-1].start;
????????file>>thread_info[threadNum-1].time;
????????totaltime+=thread_info[threadNum-1].time;
????????switch(thread_info[threadNum-1].type)
????????{
????????case?‘W‘:
????????????printf(“Creating?Thread?%d??for?writing.\n“thread_info[threadNum-1].num);
????????????thread[threadNu

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-12-26?17:34??read_write\bin\
?????目錄???????????0??2015-12-26?17:36??read_write\bin\Debug\
?????文件??????973622??2015-12-26?17:36??read_write\bin\Debug\read_write.exe
?????文件????????3525??2015-12-26?17:36??read_write\main.cpp
?????文件????????3278??2015-12-26?17:33??read_write\main.cpp.save
?????目錄???????????0??2015-12-26?17:34??read_write\obj\
?????目錄???????????0??2015-12-26?17:36??read_write\obj\Debug\
?????文件???????19717??2015-12-26?17:36??read_write\obj\Debug\main.o
?????文件????????1115??2015-12-26?17:31??read_write\read_write.cbp
?????文件?????????138??2015-12-26?17:54??read_write\read_write.depend
?????文件?????????320??2015-12-27?21:42??read_write\read_write.layout
?????文件?????????322??2015-12-27?21:08??read_write\read_write.layout.save
?????文件??????????53??2015-12-26?17:54??read_write\thread.dat

評論

共有 條評論