extended code to advanced input functionality
This commit is contained in:
parent
bb32f2abc5
commit
58cf91a06d
14 changed files with 40 additions and 0 deletions
23
OS/C/theory/sync/semaextraposts.c
Normal file
23
OS/C/theory/sync/semaextraposts.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <sys/semaphore.h>
|
||||
|
||||
sem_t my_semaphore;
|
||||
|
||||
int main(){
|
||||
sem_init(&my_semaphore, 0, 5);
|
||||
int sem_val;
|
||||
sem_getvalue(&my_semaphore, &sem_val);
|
||||
printf("Semaphore value after extra posts: %d\n", sem_val);
|
||||
|
||||
sem_post(&my_semaphore);
|
||||
sem_post(&my_semaphore);
|
||||
sem_post(&my_semaphore);
|
||||
|
||||
sem_getvalue(&my_semaphore, &sem_val);
|
||||
printf("Semaphore value after extra posts: %d\n", sem_val);
|
||||
|
||||
sem_destroy(&my_semaphore);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue