免费获取|
论文天下网
  • 论文天下网 |
  • 原创毕业论文 |
  • 论文范文 |
  • 论文下载 |
  • 计算机论文 |
  • 论文降重 |
  • 毕业论文 |
  • 外文翻译 |
  • 免费论文 |
  • 开题报告 |
  • 心得体会 |

当前位置:论文天下网 -> 免费论文 -> 计算机论文

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

DWORD)(((ThreadInfo*)(p))->delay *INTE_PER_SEC);
 m_persist=(DWORD)(((ThreadInfo*)(p))->persist *INTE_PER_SEC);
 Sleep(m_delay);
 
 printf("Write thread %d sents the writing require.\n",m_serial);
 //等待资源
 EnterCriticalSection(&RP_Write);
 //写文件
 printf("Writer thread %d begins to write to the file.\n",m_serial);
 Sleep(m_persist);

 //退出线程
printf("Write thread %d finished writing to the file.\n",m_serial);
 //释放资源
 LeaveCriticalSection(&RP_Write);
}

//////////////////////////////////////////////////////////////
//读者优先处理函数
//file:文件名

void ReaderPriority(char *file)
{
 DWORD n_thread=0;           //线程数目
 DWORD thread_ID;            //线程ID
 DWORD wait_for_all;         //等待所有线程结束
 //互斥对象
 HANDLE h_Mutex;
 h_Mutex=CreateMutex(NULL,FALSE,"mutex_for_readcount");

 //线程对象的数组
 HANDLE h_Thread[MAX_THREAD_NUM];
 ThreadInfo thread_info[MAX_THREAD_NUM];

 readcount=0;               //初始化readcount
 InitializeCriticalSection(&RP_Write);        //初始化临界区
 ifstream inFile;
 inFile.open (file);
 printf("Reader 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)(RP_ReaderThread),&thread_info[i],0,&thread_ID);
  }
  else
  {
   //创建写线程
   h_Thread[i]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(RP_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");
}

////////////////////////////////////////////////////////
//写者优先---读者线程
//P:读者线程信息


void WP_ReaderThread(void *p)
{

 //互斥变量
 HANDLE h_Mutex1;
 h_Mutex1=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"mutex1");
 HANDLE h_Mutex2;
    h_Mutex2=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"mutex2");

 DWORD wait_for_mutex1;            //等待互斥变量所有权
 DWORD wait_for_mutex2;
 DWORD m_delay;                   

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

相关论文
上一篇:C# 考务和成绩管理系统 下一篇:计算机公司销售业务管理系统
推荐论文 本专业最新论文
Tags:基于 读者 问题 read write problem 实现 【返回顶部】

相关栏目

自动化相关
计算机论文
工程管理论文
法律论文
医学论文
人力资源
电子专业
电气工程
英语论文
行政管理
电子商务
社科文学
教育论文
物流专业
金融专业
财务管理
会计专业
化学化工材料科学
电子通信
环境科学
经济类
机械模具类
报告,总结,申请书
其他专业论文


关于我们 | 联系方式 | 论文说明 | 网站地图 | 免费获取 | 钻石会员 | 原创毕业论文

 

论文天下网提供论文检测,论文降重,论文范文,论文排版,网站永久域名WWW.GEPUW.NET

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

Copyright@ 2009-2022 GEPUW.NET 论文天下网 版权所有