Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/shm.h>
- #include <sys/sem.h>
- #include "settings.h"
- #include "semaphore.h"
- int main(int argc, char* argv[]) {
- /* Create semaphores for each buffer */
- int empty, full, conditions; //id's of buffers
- empty = initialize_sem_array((int)EMPTY, 3, 0); //init with key, number of sems, init value
- full = initialize_sem_array((int)FULL, 3, 9);
- conditions = initialize_sem_array((int)CONDITIONS, 2, 0); //production limitations as specified
- /* Create shared memory for buffers
- *
- * bufX[MAX] holds the index of the 1st element in the queue
- */
- int idA, idB, idC;
- int *bufA, *bufB, *bufC;
- idA = shmget(BUFA, (MAX + 1) * sizeof(int), IPC_CREAT | 0600);
- idB = shmget(BUFB, (MAX + 1) * sizeof(int), IPC_CREAT | 0600);
- idC = shmget(BUFC, (MAX + 1) * sizeof(int), IPC_CREAT | 0600);
- bufA = (int*)shmat(idA, NULL, 0);
- bufB = (int*)shmat(idB, NULL, 0);
- bufC = (int*)shmat(idC, NULL, 0);
- if (bufA == NULL || bufB == NULL || bufC == NULL) {
- perror("main: Creating shared memory for buffers failed");
- }
- bufA[0] = 7;
- //printf("A: %i\n", bufA[0]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement