/* * Illustrate setting up a mutex * New File Mar 23,1989 * Author Jerry LeVan * */ #include #include #include #include #define COUNT 1 /* How many we are going to create */ #define PERM 0666 /* all can read write */ #define KEY 'JHL ' /* our key */ main() { int id; int result; /* struct sembuf { short sem_num; short sem_op; short sem_flag; } op[1]; */ struct sembuf op[1]; id = semget(KEY,0,0); printf("status of get key = %d\n",id); if(id == -1) {perror("Bad Semaphore ID fetch"); exit();} /* initialize the op data structure */ op[0].sem_num = 0; /* the first one */ op[0].sem_op = 1; /* add 1 now */ op[0].sem_flg = 0; /* no options */ /* now try to modify the semaphore */ result = semop(id,op,1); if(result == -1){ perror("Bad Signal"); exit();} printf("Set semaphore\n"); }