亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? lift simulator.c

?? it s a lift simulator, use operating system concept call mutex to implenment a lift. I do it prefect
?? C
字號:
/********************
159335 Assignment 2 lift simulator program
********************/
#include <stddef.h>     //   159.335 Assignment 2
#include <stdio.h>      //   Lift Simulator - M.Johnson 2000
#include <stdlib.h>     //   This was written for GCC but it
#include <windows.h>    //   may also work with Borlandc
#include <conio.h>      //   and Visual C++
                        //   lines starting with --- are unfinished

#define semaphore HANDLE

void wait(semaphore h) {     // wait for a semaphore
	WaitForSingleObject( h, MAXLONG);
}

void signal(semaphore h) {   // signal a semaphore
	ReleaseSemaphore(h,1,NULL);
}

semaphore create(int v) {    // create a semaphore with value v
	return CreateSemaphore(NULL,(long)v, MAXLONG, NULL);
}

//
//	The size of the buliding
//
#define NLIFTS 4        /* the number of lifts in the buliding */
#define NFLOORS 20      /* the number of floors in the building */
#define NPEOPLE 20      /* the number of people in the building */
#define MAXNOINLIFT 10  /* maximum lift capacity */
//
//	Some times (all in milliseconds)
//
//#define LIFTSPEED 50
//#define GETINSPEED 50 
//#define GETOUTSPEED 50
//#define PEOPLESPEED 100

#define LIFTSPEED 0    /* the time it takes for the lift to move one floor */
#define GETINSPEED 0   /* the time it takes to get into the lift */
#define GETOUTSPEED 0  /* the time it takes to get out of the lift */
#define PEOPLESPEED 1 /* the maximum time a person spends on a floor */
//
//	Directions
//
#define UP 1
#define DOWN -1

#define rnd(i) (rand()%(i))  /* a random number from 0..i-1 inclusive */
int rand_seed=123456;
#define randomise() srand(rand_seed);rand_seed=rand();
//
//	Information about a floor in the building
//
typedef struct {
  int waitingtogoup;    /* the number of people waiting to go up */
  int waitingtogodown;  /* the number of people waiting to go down */
  semaphore up_arrow;   /* people going up wait on this */
  semaphore down_arrow; /* people going down wait on this */
} Floor_info;
//
//	Information about a lift
//
typedef struct {
  int no;               /* which lift is it */
  int position;         /* which floor it is on */
  int direction;        /* going UP or DOWN */
  int peopleinlift;     /* number of people in the lift */
  int stops[NFLOORS];   /* for each stop how many people are waiting to get off */
  semaphore stopsem[NFLOORS]; /* people in the lift wait on one of these */
} Lift_info;
//
//	Some global variables
//
semaphore mutex,//mutex to protect critical sections
          InLift[NFLOORS];//people in each floor, wait for this to get into lift

Floor_info floor[NFLOORS];
Lift_info *GetInLift;//global variable, tell person which lift to get in
//
//	print a character c on the screen at position (x,y)
//
void char_at_xy(int x,int y,char c) {
	wait(mutex);//make it into critical section, avoid each thread want to draw on screen at the same time
#ifdef __GNUC__
	gotoxy(x,y);
#else
	gotoxy(x+1,y+1);
#endif  
	Sleep(1);        // slow things down for NT
	printf("%c",c);  /* the char itself */
	signal(mutex);
}
//
//	Tell everybody that is waiting to go in a certain direction
// to get into the lift. If the lift was empty then move it in the correct direction.
//
void getintolift(Lift_info *l,int direction) {
  int *waiting;
  semaphore *s;
  
  if(direction==UP) {  /* if going up */
	 s=&floor[l->position].up_arrow;  /* use this semaphore */
	 waiting=&floor[l->position].waitingtogoup;  /* and this is the number waiting */
  }
  else {               /* if going down */
	 s=&floor[l->position].down_arrow; /* use this semaphore */
	 waiting=&floor[l->position].waitingtogodown; /* and this is the number waiting */
  }
  wait(InLift[l->position]);//aaaa block the semaphore, people want to get in 
  // make it into critical section, people ready to get in
  while(*waiting) {    /* for all people waiting */
	 if(!l->peopleinlift)  /* if the lift is empty */
		l->direction=direction; /* set direction */
	 if(l->peopleinlift<=MAXNOINLIFT && *waiting) {
		l->peopleinlift++;  /* one more in the lift */
		char_at_xy(NLIFTS*4+floor[l->position].waitingtogodown+floor[l->position].waitingtogoup,
						 NFLOORS-l->position,' '); /* erase from screen */
		(*waiting)--;       /* one less waiting */
		Sleep(GETINSPEED);  /* wait a short time */
		if (l) {
		 wait(mutex); // enter critical section, protect lift info
		 GetInLift=l;  /* tell the person which lift it is, assign to the gobal variable */
		 signal(mutex); /* and wake them up*/
		 }
		else return;
      }
	  else {
		 break;
	  }
  }
  signal(*s); //wake up up_arrow or down_arrow,this two semaphore will be 1, others can go up or down wait for this
  signal(InLift[l->position]); //release this level of people waiting
}
//
//	A lift
//
unsigned long lift_thread(void *p) {
  Lift_info l;
  int i;
  int no=(int)p;
  
  l.no=no;          /* set the no for this lift */
  l.position=0;     /* set the initial position */
  l.direction=1;    /* and direction */
  l.peopleinlift=0; /* empty */
  randomise();
  for(i=0;i<NFLOORS;i++) {
	 l.stops[i]=0;   /* nobody is waiting in the lift to go anywhere */
	 l.stopsem[i]=create(0);
	 InLift[i]=create(1);//initialise each level of InLift by 1, ready for wait
  }
  Sleep(rnd(1000)); /* wait for a while */
  while(1) {        /* do forever */
	 char_at_xy(no*4+1,NFLOORS-l.position,0xdb); /* draw current position of lift */
	 Sleep(LIFTSPEED);  /* wait a while */
	 while (l.stops[l.position]!=0) {  /* drop off all passengers */
		l.peopleinlift--;        /* one less in lift */
		l.stops[l.position]--;   /* one less waiting */
		Sleep(GETOUTSPEED);      /* wait a while */
		signal(l.stopsem[l.position]); /* tell them to get out */  //aaa when it is in position, get out
		if(!l.stops[l.position]) /* if it was the last one */
			char_at_xy(no*4+1+2,NFLOORS-l.position,' ');  /* remove the - */
	 } 
	 if(l.direction==UP || !l.peopleinlift)  /* if the lift is going up or is empty */
		getintolift(&l,UP);      /* pick up passengers waiting to go up */
	 if(l.direction==DOWN || !l.peopleinlift) /* if the lift is going down or is empty */
		getintolift(&l,DOWN);    /* pick up passengers waiting to go down */
	 char_at_xy(no*4+1,NFLOORS-l.position,(char)(l.direction+1?' ':0xb3));  /* erase the lift on the screen */
	 l.position+=l.direction;   /* move it */
	 if(l.position==0 || l.position==NFLOORS-1)  /* if it is at the top or bottom */
		l.direction=-l.direction; /* change direction */
  }
}
//
//	A person
//
unsigned long person_thread(void *p) {
  int from=0,to; /* start on the ground floor */
  Lift_info *l;
  randomise();
  while(1) {     /* stay in the building forever */
	 Sleep(rnd(PEOPLESPEED)); /* work for a while */
	 do
		to=rnd(NFLOORS);
	 while(to==from);	/* pick a different floor to go to*/
	 if(to>from) {	/* if we are going up */
		floor[from].waitingtogoup++;
	   char_at_xy(NLIFTS*4+ floor[from].waitingtogoup
		 +floor[from].waitingtogodown,NFLOORS-from,0xdc);
		wait(floor[from].up_arrow);	/* wait for the lift to arrive */
	}
	 else {  /* if we are going down */
		floor[from].waitingtogodown++;
	   char_at_xy(NLIFTS*4+ floor[from].waitingtogoup
		 +floor[from].waitingtogodown,NFLOORS-from,0xdc);
	   wait(floor[from].down_arrow);	/* wait for the lift to arrive */
	 }
	 if(GetInLift) {
	  wait(mutex);//protect lift info, critical section
	  l=GetInLift; /* which lift are we geting in to */  //aaaa
	  l->stops[to]++; /* press the button for the floor we want */
	  signal(mutex); 
	  }
	  else return; 
	  if(l->stops[to]==1)  /* light up the button if we were the first */
		char_at_xy(l->no*4+1+2,NFLOORS-to,'-');
		wait(l->stopsem[to]);	/* wait until we get to the right floor */  //wait until people get out in the 'to' position
		from=to;  /* we have reached our destination */
	}
}
//
//	Print the building on the screen
//
void printbuilding(void) {
  int l,f;

  clrscr();                  /* clear the screen added for borlandc */
  _setcursortype(_NOCURSOR); // added for borlandc and gcc
  printf("\xda");
  for(l=0;l<NLIFTS-1;l++)         /* roof */
	 printf("\x0c4\x0c2\x0c4\x0c2");
  puts("\x0c4\x0c2\x0c4\x0bf");
  for(f=NFLOORS-1;f>=0;f--)
	 for(l=0;l<NLIFTS;l++) {       /* floors */
		printf("\x0b3\x0b3\x0b3 ");
		if(l==NLIFTS-1)
			puts("\x0b3");
	 }
  printf("Lift Simulation - Press CTRL-Break to exit");
}
//
//	main starts the threads and then just sits there.
//
int main() {
  unsigned long i,id;
  /* initialise any other semaphores */
  mutex=create(1); // initialise mutex by 1, ready for wait
  
  for(i=0;i<NFLOORS;i++) {
	 floor[i].waitingtogoup=0;     /* initialise the building */
	 floor[i].waitingtogodown=0;
	 floor[i].up_arrow=create(0);
	 floor[i].down_arrow=create(0);
  }

  printbuilding();        /* print the buildong on the screen */
  for(i=0;i<NLIFTS;i++)   /* create the lift threads */
	CreateThread(NULL,0,lift_thread,(void *)i,0,&id);

  for(i=0;i<NPEOPLE;i++)  /* create the people threads */
	CreateThread(NULL,0,person_thread,(void *)i,0,&id);

  Sleep(86400000); /* go to sleep for 86400 seconds (one day) */
  return(1);
}


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品久久久久久无| 91麻豆精品国产| 国产人成亚洲第一网站在线播放| 免费人成精品欧美精品 | 91麻豆蜜桃一区二区三区| 中文字幕亚洲成人| 色噜噜狠狠色综合中国| 五月婷婷久久综合| 久久综合色8888| 日本韩国欧美三级| 91成人在线免费观看| 欧美系列亚洲系列| 国产精品亚洲一区二区三区妖精 | 国产在线视频一区二区三区| 亚洲欧洲另类国产综合| 亚洲色图19p| 国产视频911| 欧美一级高清片在线观看| 波多野结衣91| 久久精品久久精品| 一区二区欧美视频| 久久久久久久久久久黄色| 欧美精品在线观看一区二区| 成人免费va视频| 人人精品人人爱| 国产精品一卡二| 一本大道久久a久久综合| 国模少妇一区二区三区| 成人亚洲一区二区一| 91蝌蚪porny成人天涯| 欧美日韩国产综合视频在线观看| av在线一区二区三区| 欧美性大战久久久久久久| 日韩午夜av电影| 国产午夜精品在线观看| 夜夜操天天操亚洲| 久久99热狠狠色一区二区| 波多野结衣中文一区| 激情五月婷婷综合网| 97成人超碰视| av网站一区二区三区| 6080国产精品一区二区| 国产日韩欧美高清| 婷婷综合五月天| 成人动漫中文字幕| 欧美一级片在线| 精品人伦一区二区色婷婷| 综合电影一区二区三区 | 亚洲天堂精品视频| 蜜臀99久久精品久久久久久软件| 亚洲成人免费看| 亚洲高清免费视频| 午夜精品久久久久久| 懂色av一区二区三区免费观看| 国产91精品欧美| 日韩三级av在线播放| 亚洲欧美日韩国产一区二区三区 | 日韩美一区二区三区| 日韩一区国产二区欧美三区| 18成人在线观看| 国产一区二区三区黄视频 | 亚洲欧洲精品成人久久奇米网| 日韩av中文在线观看| 久久精品理论片| 欧美日韩免费电影| 亚洲精品成a人| 五月天网站亚洲| 一本到高清视频免费精品| 久久精品人人爽人人爽| 麻豆精品视频在线观看免费| 欧美日本韩国一区| 亚洲成在人线在线播放| 色系网站成人免费| 亚洲欧美日韩精品久久久久| av激情亚洲男人天堂| 中文字幕精品一区二区三区精品 | 色综合久久综合| 中文字幕日韩一区| 99国产精品久久久久久久久久 | 亚洲自拍偷拍网站| 麻豆精品视频在线观看免费| 8v天堂国产在线一区二区| 亚洲电影一区二区| 欧美日韩日日夜夜| 久久精品视频网| 国产美女娇喘av呻吟久久| 精品国产凹凸成av人网站| |精品福利一区二区三区| 97精品电影院| 亚洲国产成人高清精品| 欧美一区永久视频免费观看| 日本va欧美va精品发布| 欧美xxxxx裸体时装秀| 精彩视频一区二区| 欧美日韩精品欧美日韩精品一 | 久久久久久免费| 懂色av一区二区三区蜜臀| 国产精品电影院| 国产一区在线精品| 国产精品另类一区| 狠狠色狠狠色综合系列| 欧美经典一区二区三区| 97精品国产露脸对白| 亚洲国产成人91porn| 欧美xxxx在线观看| 99久久国产综合色|国产精品| 亚洲精品自拍动漫在线| 欧美一级国产精品| 不卡av电影在线播放| 日韩有码一区二区三区| 日本精品裸体写真集在线观看| 日韩和欧美的一区| 国产精品麻豆99久久久久久| 欧美日韩中文另类| 国产91富婆露脸刺激对白| 亚洲精品国产无套在线观| 欧美高清视频www夜色资源网| 激情综合色播五月| 一区二区成人在线| www国产成人免费观看视频 深夜成人网| 成人午夜免费电影| 秋霞午夜鲁丝一区二区老狼| 成人欧美一区二区三区小说| 日韩视频一区二区| 91丝袜美女网| 国产一区二区三区四区五区美女 | 亚洲成人三级小说| 国产午夜精品美女毛片视频| 欧美精品乱码久久久久久按摩| 丁香五精品蜜臀久久久久99网站| 亚洲图片一区二区| 亚洲欧洲日韩av| 国产亚洲欧美一级| 日韩女同互慰一区二区| 欧美日韩五月天| 色狠狠色噜噜噜综合网| 国产美女精品在线| 看电视剧不卡顿的网站| 亚洲国产色一区| 亚洲精品视频一区| 自拍偷拍亚洲欧美日韩| 国产日韩一级二级三级| 精品成人免费观看| 精品国产一区二区亚洲人成毛片| 欧美日韩免费一区二区三区 | 一级特黄大欧美久久久| 中文字幕一区二区三区蜜月| 久久久久成人黄色影片| 日韩一级大片在线| 欧美一级搡bbbb搡bbbb| 欧美丰满少妇xxxxx高潮对白 | 婷婷丁香久久五月婷婷| 亚洲一区二区三区四区的| 中文字幕亚洲欧美在线不卡| 国产精品人人做人人爽人人添| 欧美国产一区视频在线观看| 久久精品视频一区二区| 国产性做久久久久久| 国产精品素人视频| 中文字幕精品综合| 亚洲欧美怡红院| 亚洲精品日日夜夜| 亚洲成av人片在www色猫咪| 亚洲尤物在线视频观看| 日韩精品一二三四| 美腿丝袜在线亚洲一区| 国内精品伊人久久久久av一坑| 精品午夜久久福利影院| 国产乱码一区二区三区| 成人综合婷婷国产精品久久蜜臀| av在线一区二区| 欧美亚洲愉拍一区二区| 日韩欧美美女一区二区三区| 国产亚洲精品精华液| 国产精品久久久久久久久免费相片| 日韩美女视频一区二区 | 日韩亚洲欧美在线| 久久久久9999亚洲精品| 1024成人网色www| 五月天婷婷综合| 国产成人日日夜夜| 免费在线视频一区| 国产一区二区三区视频在线播放| 成人精品在线视频观看| 欧美性色黄大片| 精品国产免费一区二区三区香蕉| 国产精品青草久久| 亚洲午夜视频在线| 国产一区二区伦理| 欧洲精品中文字幕| 91蝌蚪porny九色| 欧美一级黄色片| 国产精品乱码妇女bbbb| 五月天一区二区三区| 盗摄精品av一区二区三区| 在线成人av影院| 国产精品国产三级国产普通话99| 午夜精品福利一区二区蜜股av| 成人午夜电影久久影院| 欧美猛男男办公室激情|