Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // P1.c
- #include <stdio.h>
- #include <shared.h>
- int main() {
- sem_t sem;
- sem_t empty;
- sem_t full;
- sem = sem_init(91011);
- empty = sem_init(91012);
- full = sem_init(91013);
- char *buff;
- char b;
- int i;
- buff = (char *)getmem(9101);
- for (char k = 'a'; k <= 'z'; ++k)
- {
- PS(full);
- PS(sem);
- printf("%c\n", *buff);
- VS(empty);
- VS(sem);
- for (i = 0; i < 1000000; i++);
- }
- sem_remove(sem);
- sem_remove(empty);
- sem_remove(full);
- printf("\nConsumer process ended\n");
- }
- // P2.c
- #include <stdio.h>
- #include <shared.h>
- int main() {
- sem_t sem;
- sem_t empty;
- sem_t full;
- sem = sem_init(91011);
- empty = sem_init(91012);
- full = sem_init(91013);
- sem_set(sem, 1);
- sem_set(empty, 1);
- sem_set(full, 0);
- char *buff;
- char b;
- int i;
- buff = (char *)getmem(9101);
- for (b = 'a'; b <= 'z'; ++b) {
- PS(empty);
- PS(sem);
- *buff = b;
- VS(sem);
- VS(full);
- for (i = 0; i < 1000000; i++);
- }
- printf("Producer process ended\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement