基本信息
源码名称:C++实现的简单的操作系统信号量机制.cpp
源码大小:6.58KB
文件格式:.CPP
开发语言:C/C++
更新时间:2020-12-31
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍


#include<iostream.h>
#include<stdlib.h>
#include<conio.h>

struct MES{
int sender;
int size,text;
MES *next;
} aa;

struct PCB{
  int id;
  int priority;
  int nextwr;
  int ir;
  MES *mq;
  char status;
} p[4];

struct semaphore{
int value;
int firstwr;
char *name;
int no;
} sem1,sem2;
int savearea[4][4],s[4][3];
int exe,I,addr,s1,s2,c1,c2,c3;
int R,T,W,C,seed,in=1;
int (*pr[4])(int);
void more();

void create(int k)
{int i;
 cout<<"Input the priority of process "<<k<<" : ";
 more();
 cin>>i;
 p[k].id=k;
 p[k].ir=0;
 p[k].priority=i;
 p[k].status='R';
 p[k].nextwr=R;
 R=k;
 cout<<"process "<<k<<" is  ready \n";
 more();
}
float   random()
{
  int   m;
  if(seed<0)    m=-seed;
else    m=seed;
  seed=(25173 * seed 13849) % 65536;
  return  (m / 32767.0);
}

  void more()
{ in ;
  if(in%24==0)
  {cout<<"             ";
   getch();cout<<endl;}
 }

 int time(int i)
{ float x=random();
  switch(i)
 {case 1:if(x>=0.33){cout<<"time out.\n";more();return 1;}return 0;
  case 2:if(x>=0.66||x<0.33) {cout<<"Time out.\n";more();return 1;} return 0;
  case 3:if(x<0.66){cout<<"time out.\n"; more();return 1;}return 0;
  }return 0;
}

void send(int receiver,MES q)
{ MES *t,*m=new MES;
  m->sender=exe;
  m->size=q.size;
  m->text=q.text;
  m->next=0;
 if(p[receiver].mq==0) p[receiver].mq=m;
 else {t=p[receiver].mq;
       while(t->next) t=t->next;
       t->next=m;
      }
  cout<<"process "<<exe<<" sends a message to process "<<receiver<<"\n";
  more();
}
......