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 sem1;
- sem_t empty;
- sem_t full;
- sem_t sem2;
- sem_t empty2;
- sem_t full2;
- sem1 = sem_init(120621646);
- empty = sem_init(220621646);
- full = sem_init(320621646);
- sem2 = sem_init(1120621646);
- empty2 = sem_init(2220621646);
- full2 = sem_init(3320621646);
- char *buff;
- char b;
- int i;
- buff = (char *)getmem(520621646);
- for (char k = 'A'; k <= 'Z'; ++k)
- {
- PS(full2);
- PS(sem2);
- PS(sem1);
- printf("%c\n", *buff);
- VS(empty);
- VS(sem1);
- VS(sem2);
- for (i = 0; i < 1000000; i++);
- }
- sem_remove(sem1);
- sem_remove(empty);
- sem_remove(full);
- sem_remove(sem2);
- sem_remove(empty2);
- sem_remove(full2);
- printf("\nConsumer process ended\n");
- }
- // P2.c
- #include <stdio.h>
- #include <shared.h>
- int main() {
- sem_t sem1;
- sem_t empty;
- sem_t full;
- sem_t sem2;
- sem_t empty2;
- sem_t full2;
- sem1 = sem_init(120621646);
- empty = sem_init(220621646);
- full = sem_init(320621646);
- sem2 = sem_init(1120621646);
- empty2 = sem_init(2220621646);
- full2 = sem_init(3320621646);
- sem_set(sem1, 1);
- sem_set(empty, 1);
- sem_set(full, 0);
- sem_set(sem2, 1);
- sem_set(empty2, 1);
- sem_set(full2, 0);
- char *buff;
- char b;
- int i;
- buff = (char *)getmem(420621646);
- for (b = 'A'; b <= 'Z'; ++b)
- {
- PS(empty);
- PS(sem1);
- PS(sem2);
- *buff = b;
- VS(sem1);
- VS(full);
- VS(sem2);
- for (i = 0; i < 1000000; i++);
- }
- printf("Producer process ended\n");
- }
- // cap.c
- #include <stdio.h>
- #include <shared.h>
- #include <ctype.h>
- int main() {
- sem_t sem1;
- sem_t empty;
- sem_t full;
- sem_t sem2;
- sem_t empty2;
- sem_t full2;
- sem1 = sem_init(120621646);
- empty = sem_init(220621646);
- full = sem_init(320621646);
- sem2 = sem_init(1120621646);
- empty2 = sem_init(2220621646);
- full2 = sem_init(3320621646);
- char *buff;
- char *bfrz;
- char b;
- int i;
- buff = (char *)getmem(420621646);
- bfrz = (char *)getmem(520621646);
- for (char k = 'A'; k <= 'Z'; ++k)
- {
- PS(full);
- PS(sem1);
- PS(sem2);
- b = *buff;
- *bfrz = toupper(b);
- VS(sem1);
- VS(sem2);
- VS(full2);
- for (i = 0; i < 1000000; i++);
- }
- printf("\nCapitalization finished");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement