explain any two methods of implementing


Explain any two methods of implementing interacting processes.

Two methods of implementing interacting process are given below:

(i) Shared memory solution: In this scheme requires that such processes share a common buffer pool and the code for implementing the buffer is written through the application programmer.

For illustration, a shared-memory solution can be given to the bounded- buffer problem. The producer and consumer processes share the subsequent variables:

#define BUFFER_SIZE 10

Typedef struct{

..........

 }item;

Item buffer[BUFFER_SIZE];

int in=0;

int out=0;

The shared buffer is implemented like a circular array along with two logical pointers: in/out. The variable in-points to the next free position into the buffer, out-points to the first full position into the buffer. The buffer is empty while in==out; the buffer is full while (( in + 1)%BUFFER_SIZE)==out.

The producer process has a local variable nextProduced wherein the new item to be produced is stored:

while(1){

/* produce and item in nextProduced */ While(((in + 1)%BUFFER_SIZE)==out)

; // don't do anything

Buffer[in]=nextProduced;

in =(in+1)% BUFFER_SIZE;}

The consumer process has a local variable nextConsumed in which the item to be consumed is stored:

while(1){

while(in==out)

; // don't do anything

nextConsumed = buffer[out];

out=(out +1)% BUFFER_SIZE;

/* consume the item in nextConsumed */}

(ii) Inter process Communication: The OS gives the means for cooperating processes to communicate with each other through an inter-process communication (IPC) facility. IPC gives a mechanism to allow processes to communicate and to synchronize their actions without sharing similar address space. IPC is particularly helpful in a distributed environment where the communicating processes may reside on various computers connected with a network. IPC is best implemented through message passing system where communication among the user processes is accomplished by the passing of messages. An

Inter-process communication facility gives at least the two operations: send(message) and receive(message).

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: explain any two methods of implementing
Reference No:- TGS0276865

Expected delivery within 24 Hours