Last active
August 29, 2015 13:56
-
-
Save kotaroito/9071625 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <sys/sem.h> | |
| int main(void) | |
| { | |
| int semid; | |
| union semun { | |
| int val; | |
| struct semid_ds *buf; | |
| unsigned short *array; | |
| } arg; | |
| // semaphoreの集合(ここでは要素数1)を得る | |
| if ((semid = semget(IPC_PRIVATE, 1, 0666)) < 0) { | |
| perror("semget"); | |
| } | |
| // semaphore集合の要素番号0に対して、1をセットする | |
| arg.val = 1; | |
| if (semctl(semid, 0, SETVAL, arg) < 0) { | |
| perror("semctl:SETVAL"); | |
| } | |
| printf("semaphore:%d\n", semctl(semid, 0, GETVAL)); | |
| // semaphoreを削除する | |
| if (semctl(semid, 0, IPC_RMID) < 0) { | |
| perror("semctl:IPC_RMID"); | |
| } | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment