導航:首頁 > 編程語言 > pv操作代碼

pv操作代碼

發布時間:2025-05-05 15:50:38

Ⅰ 急求關於操作系統PV操作的程序代碼C或C++都可以,在線等啊!!!!!!!!!!

完整程序要花不少時間調試的,我這里給你一個實現PV操作的程序吧,5個人搶3個位子,這個你們上課應該會講的,通過幾個pv操作就可以實現,只要把我這里寫的pv操作的代碼用上就可以了。程序是在linux系統下調試的。pv操作分別對應下面的up和down(我們老師習慣用這種稱呼,於是就在代碼中也這么用了)
#include <stdio.h>#include <signal.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <sys/times.h>#include <fcntl.h>#include <stdlib.h>#include <sys/sem.h> //include header file for semaphore #define FILE_SIZE 11#define NO_PROC 10 int DelayCount = 0; int readerID = 0;int writerID = 0; char* shared_buffer; int Delay100ms = 0; int* shared_buffer2;////////Variables for semaphoreoperations/////int semid;// the followings are not necessary to definehere, but just for conveniencekey_t semkey;struct sembuf operation[1];short sarray[2];int ret_val;/////////////////////////////////////////////// void init_sem(){ int*rc; //getkey semkey=ftok("/dev/null",12); if( semkey == (key_t) -1 ) { printf("main:ftok() failed\n"); exit(-1); } printf("semkeygenerated\n"); //getsemaphore set semid= semget( semkey, 2, 0666 | IPC_CREAT | IPC_EXCL ); if( semid == -1 ) { printf("main: semget()failed\n"); exit(-1); } //setthe two semaphores to 1; sarray[0]=1; sarray[1]=1; ret_val=semctl(semid,1, SETALL, sarray); if(ret_val==-1) { printf("main:semctlerror\n"); exit(-1); } printf("ddddd\n"); //setreader count rc=(int*)(&shared_buffer[FILE_SIZE]); //printf("%d\n",*shared_buffer2); *rc=0; printf("RC:%d\n",*rc);} void down(int i) //i=0, 1{ operation[0].sem_num=i; operation[0].sem_op=-1; operation[0].sem_flg=0; ret_val=semop(semid,operation,1);} void up(int i){ operation[0].sem_num=i; operation[0].sem_op=1; operation[0].sem_flg=0; ret_val=semop(semid,operation,1);}

閱讀全文

與pv操作代碼相關的資料

熱點內容
logo程序下載 瀏覽:873
led屏幕編程是什麼意思 瀏覽:338
在linux如何修改文件內容 瀏覽:378
如何找出a列不等於b列的數據 瀏覽:472
金磚五國青年哪個app好 瀏覽:442
word2007橫向縱向混排 瀏覽:13
有什麼免費看英語單詞的app嗎 瀏覽:386
蘋果5s一直搜索網路 瀏覽:51
蘋果數據線怎麼分正負極線 瀏覽:575
javascript基本類型 瀏覽:860
app後台常用開發語言 瀏覽:982
魅族手機微信後台運行 瀏覽:116
excel多個工作表復制到另一個文件 瀏覽:87
word圖片題注組合 瀏覽:443
jsnewid 瀏覽:707
網頁管理員賬戶密碼忘記了 瀏覽:431
四年級英語學什麼app好 瀏覽:240
淘寶固定背景代碼生成器 瀏覽:290
編程題目哪個平台好 瀏覽:479
極品飛車蘋果 瀏覽:821

友情鏈接