网站地图| 免费获取|
毕业论文网
  • 网站首页|
  • 论文范文|
  • 论文降重|
  • 职称论文发表|
  • 合作期刊|
  • 论文下载|
  • 计算机论文|
  • 外文翻译|
  • 免费论文|
  • 论文资料|
  • 论文开题报告
搜索

当前位置:毕业论文网 -> 免费论文 -> 计算机论文 -> 基于C++的读者与写者问题read—write problem的实现(七)
计算机论文资料| ASP设计| Delphi| VB设计| JSP设计| ASP.NET设计| VB.NET| java设计| VC| pb| VS| dreamweaver| c#.net| vf| VC++| 计算机论文范文| 论文下载| 自动化论文

基于C++的读者与写者问题read—write problem的实现(七)

最新活动:微信集50个赞就可获取任意一篇钻石会员文档。详情见微信集赞换文档
基于C++的读者与写者问题read—write problem的实现(七) sp;  //修改写者数目
 if(writecount==1)
 {
  EnterCriticalSection(&cs_Read);
 }
 ReleaseMutex(h_Mutex3);
 EnterCriticalSection(&cs_Write);
 printf("Writer thread %d begins to write to the file.\n",m_serial);
 Sleep(m_persist);

 printf("Writer thread %d finished writing to the file.\n",m_serial);
 LeaveCriticalSection(&cs_Write);

 wait_for_mutex3=WaitForSingleObject(h_Mutex3,-1);
 writecount--;
 if(writecount==0)
 {
  LeaveCriticalSection(&cs_Read);
 }
ReleaseMutex(h_Mutex3);
}
/////////////////////////////////////////////
//写者优先处理函数
// file:文件名

void WriterPriority(char * file)
{
 DWORD n_thread=0;
 DWORD thread_ID;
 DWORD wait_for_all;


 HANDLE h_Mutex1;
 h_Mutex1=CreateMutex(NULL,FALSE,"mutex1");
 HANDLE h_Mutex2;
 h_Mutex2=CreateMutex(NULL,FALSE,"mutex2");
 HANDLE h_Mutex3;
 h_Mutex3=CreateMutex(NULL,FALSE,"mutex3");
 HANDLE h_Thread[MAX_THREAD_NUM];
 ThreadInfo thread_info[MAX_THREAD_NUM];

 readcount=0;
 writecount=0;
 InitializeCriticalSection(&cs_Write);
 InitializeCriticalSection(&cs_Read);
 
 ifstream inFile;
 inFile.open (file);
 printf("Writer priority:\n\n");
 while(inFile)
 {
  inFile>>thread_info[n_thread].serial;
  inFile>>thread_info[n_thread].entity;
  inFile>>thread_info[n_thread].delay;
  inFile>>thread_info[n_thread++].persist;
  inFile.get();
 }
 for(int i=0;i<(int)(n_thread);i++)
 {
  if(thread_info[i].entity==READER||thread_info[i].entity =='r')
  {
   //创建读者进程
 h_Thread[i]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(WP_ReaderThread),&thread_info[i],0,&thread_ID);
  }
  else
  {
   //创建写线程
   h_Thread[i]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(WP_WriterThread),&thread_info[i],0,&thread_ID);
  }

 }
 //等待所有的线程结束
 wait_for_all=WaitForMultipleObjects(n_thread,h_Thread,TRUE,-1);
 printf("All reader and writer have finished operating.\n");
}

/////////////////////////////////////////////////////
//主函数
int main(int argc,char *argv[])
{
 char ch;
 while(true)
 {
  printf("*************************************\n");
  printf("   1.Reader Priority\n");
  printf("   2.Writer Priority\n");
  printf("   3.Exit to Windows\n");
  printf("*************************************\n");
  printf("Enter your choice(1,2,3): ");
  do{
   ch=(char)_getch();
  }while(ch!='1'&&ch!='2'&&ch!='3');
  system("cls");
  if(ch=='3')
   return 0;
  else if(ch=='1')
  &nb

首页 上一页 4 5 6 7 8 下一页 尾页 7/8/8

基于C++的读者与写者问题read—write problem的实现(七)由毕业论文网(www.huoyuandh.com)会员上传。
原创论文资料流程 相关论文
上一篇:C# 考务和成绩管理系统 下一篇:计算机公司销售业务管理系统
推荐论文 本专业最新论文
Tags:基于 读者 问题 read write problem 实现 2010-04-12 09:49:50【返回顶部】
精彩推荐
发表论文

联系方式 | 论文说明 | 网站地图 | 免费获取 | 钻石会员 | 硕士论文资料


毕业论文网提供论文范文,论文代发,原创论文资料

本站部分文章来自网友投稿上传,如发现侵犯了您的版权,请联系指出,本站及时确认并删除  E-mail: 17304545@qq.com

Copyright@ 2009-2020 毕业论文网 版权所有