毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

读者写者问题实现操作系统课程设计 第6页

更新时间:2010-3-7:  来源:毕业论文
读者写者问题实现操作系统课程设计 第6页
 DWORD wait_for_mutex;   //等待互斥变量所有权
 DWORD m_delay;          //延迟时间
 DWORD m_ThreadRunTime;        //读文件持时续间
 int m_Threadhao;           //线程序号
 m_Threadhao=((ThreadInfo *)(p))->Threadhao;
 m_delay=(DWORD)(((ThreadInfo *)(p))->ThreadStartTime*100);//每秒时钟中断100次
 m_ThreadRunTime=(DWORD)(((ThreadInfo *)(p))->ThreadRunTime*100); Sleep(m_delay);                                  
 cout<<"写者线程 "<<m_Threadhao<<" 发出写请求."<<endl;
 wait_for_mutex=WaitForSingleObject(h_Mutex1,-1); 
 writecount++;
 if (writecount==1)
  EnterCriticalSection(&cs_Read);
 ReleaseMutex(h_Mutex1);
 EnterCriticalSection(&cs_Write);
 cout<<"写者线程 "<<m_Threadhao<<" 开始写文件."<<endl;
 Sleep(m_ThreadRunTime);
 cout<<"写者线程 "<<m_Threadhao<<" 完成写文件."<<endl;
 LeaveCriticalSection(&cs_Write);
 wait_for_mutex=WaitForSingleObject(h_Mutex1,-1); 
 writecount--;
 if(writecount == 0)
  LeaveCriticalSection(&cs_Read);
 ReleaseMutex(h_Mutex1);
}
//写者优先-----读者线程
void W_ReaderThread(void *p)
{
 HANDLE h_Mutex2, h_Mutex3;
 h_Mutex2 = OpenMutex(MUTEX_ALL_ACCESS,FALSE,"mutex_for_readcount");
 h_Mutex3 = OpenMutex(MUTEX_ALL_ACCESS,FALSE,"mutex_for_read");
 DWORD wait_for_mutex, wait_for_mutex1;
//等待互斥变量所有权
 DWORD m_delay;          //延迟时间
 DWORD m_ThreadRunTime;        //读文件持续时间
 int m_Threadhao;           //线程序号
 m_Threadhao=((ThreadInfo *)(p))->Threadhao;
 m_delay=(DWORD)(((ThreadInfo *)(p))->ThreadStartTime*100);
 m_ThreadRunTime=(DWORD)(((ThreadInfo *)(p))->ThreadRunTime*100);
 Sleep(m_delay);
 cout<<"读者线程 "<<m_Threadhao<<" 发出读请求."<<endl;
 wait_for_mutex1=WaitForSingleObject(h_Mutex3,-1);
 EnterCriticalSection(&cs_Read);
 LeaveCriticalSection(&cs_Read);
 ReleaseMutex(h_Mutex3);
 wait_for_mutex=WaitForSingleObject(h_Mutex2,-1);
 readcount++;
 if (readcount == 1)
  EnterCriticalSection(&cs_Write);
 ReleaseMutex(h_Mutex2);

 cout<<"读者线程 "<<m_Threadhao<<" 开始读文件."<<endl;
 Sleep(m_ThreadRunTime);
 cout<<"读者线程 "<<m_Threadhao<<" 完成读文件."<<endl;

 wait_for_mutex=WaitForSingleObject(h_Mutex2,-1);
 readcount--;
 if (readcount == 0)
  LeaveCriticalSection(&cs_Write);
 ReleaseMutex(h_Mutex2);

上一页  [1] [2] [3] [4] [5] [6] 

读者写者问题实现操作系统课程设计 第6页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。