MIT-Curricular/OS/C/theory/sync/semaextraposts.c

24 lines
528 B
C
Raw Normal View History

#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;
}