Skip to content

Program to demonstrate the concept of Mutual exclusion in parallel processing

Aim: Program to demonstrate the concept of Mutual exclusion in parallel processing

Source Code:

#include <stdio.h>
#include “shmlib.h”
#include <stdlib.h>
int main()
{
int i, id,id1, id2, id3;
int *inventory;
int *lock1, *lock2;
inventory=(int*)shared(sizeof(int),&id1);
lock1=(int*)shared(sizeof(int),&id2);
lock2=(int*)shared(sizeof(int),&id3);

id = create_process(3);
 lock_init(lock1);
for (i=0; i<id; i++)
{
    lock(lock1);
    *inventory = *inventory+2;
    printf(“value of inventory after producing is :%d n”, *inventory);
    unlock(lock1);
    lock(lock2);
    *inventory = *inventory – 1;
    printf(” Value of inventory after consuming: %d n”, *inventory);
    unlock(lock2); }
return 0; }

Output:

Comment bellow for your Query and Feedback

1 thought on “Program to demonstrate the concept of Mutual exclusion in parallel processing”

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!