sinat_29182323 2016-05-26 04:42 采纳率: 0%
浏览 1440

求问如何将vc读取的dat文件放进vc中输入和操作

我本来是在dat文件中按定义的线程结构体写入了线程操作,然后用vc中读取文件的方式
读取dat文件就可以执行线程操作,但是现在要求不能用到读取文件的方式,需要在项目里面直接输入线程操作然后执行,应该怎么写啊,求大神!!!

struct ThreadInfo // 定义线程数据结构
{
int serial; // 线程序号
char entity; // 线程类别(判断是读者线程还是写者线程)
double delay; // 线程延迟
double persist; // 线程读写操作持续时间
int node; // 结点位置
int nodenum; // 结点值
};

//读者优先权
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 ;                         // 初始化readcountt
InitializeCriticalSection(&RP_Write) ;  // 初始化临界区
ifstream inFile;                        // 打开文件
inFile.open(file) ;
printf("读者优先权:\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>>thread_info[n_thread].node;
   inFile>>thread_info[n_thread++].nodenum;
    inFile.get();
}

for(int i = 0; i < (int)(n_thread); i++)
{
   if(thread_info[i].entity == READER_PRINT || thread_info[i].entity == 'p')
   {      
       // 创建读者线程
      h_Thread[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(Print_Thread),&thread_info[i],0,&thread_ID);    
   }
else if (thread_info[i].entity == READER_FIND || thread_info[i].entity == 'f'){
   // 创建读者线程
   h_Thread[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(Find_Thread),&thread_info[i], 0 ,&thread_ID) ;
}
else if (thread_info[i].entity == WRITER_INSERT || thread_info[i].entity == 't'){
   // 创建写者线程
   h_Thread[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(Insert_Thread),&thread_info[i], 0 ,&thread_ID) ;
}
else if (thread_info[i].entity == WRITER_DELETE || thread_info[i].entity == 'd'){
   // 创建写者线程
   h_Thread[i] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(Delete_Thread),&thread_info[i], 0 ,&thread_ID) ;
}

}
//等待所有线程结束
wait_for_all = WaitForMultipleObjects(n_thread,h_Thread,TRUE,-1);
printf("所有的读者线程和写者线程都已经完成了操作.\n");

}

case 3:
ReaderPriority("thread.dat");
break;

  • 写回答

1条回答 默认 最新

  • sinat_29182323 2016-05-26 04:57
    关注

    有人吗。求助图片说明图片说明谢谢啦

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?