pong.c

来自「geekos 0.3.0简单的操作系统」· C语言 代码 · 共 37 行

C
37
字号
#include <conio.h>#include <process.h>#include <sched.h>#include <sema.h>#include <string.h>int main(int argc , char ** argv){  int i,j ;     	/* loop index */  int scr_sem; 		/* id of screen semaphore */  int time; 		/* current and start time */  int ping,pong;	/* id of semaphores to sync processes b & c */  time = Get_Time_Of_Day();  scr_sem = Create_Semaphore ("screen" , 1) ;   /* register for screen use */  ping = Create_Semaphore ("ping" , 1) ;      pong = Create_Semaphore ("pong" , 0) ;     for (i=0; i < 5; i++) {       P(ping);       for (j=0; j < 35; j++);       V(pong);  }  time = Get_Time_Of_Day() - time;  P (scr_sem) ;  Print ("Process Pong is done at time: %d\n", time) ;  V(scr_sem);  return (0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?