0
400views
What is shared data problem and mention various methods to resolve it? Give relevant examples.
1 Answer
0
2views

Interprocess communication refers to the communication between the different processes running in the system.  The various techniques used for IPC in the embedded system are:

Queue:

It is a first in first out (FIFO) kind of data structure. In this case there is a START and a TAIL pointer. The START pointer is with the process which is supposed to take the data from another process. The TAIL pointer is with the process that is supposed to give the data to another process. There is a special kind of queue called as circular queue. As the name says the elements are arranged in a circular manner in this queue. Special care has to be taken for the START and TAIL pointers so that they point to the correct element.

Mailbox:

Mailbox is slightly similar to the queue, but different processes can post a data into this queue. There will be a separate queue for each process. Whenever a process say 'A' wants to give a data to a process 'B'; then the process 'A' will put this data in the mailbox of process 'B'.

Pipe device:

Instead of having a mailbox, if there is a separate pipe kind of structure between all two processes that can communicate, then it is called as a pipe device. The pipe between the two processes function in the same manner as that of a queue, but only between the two processes.

Semaphore:

This the most widely used method for interprocess communication. In case a common resource is to be accessed by multiple tasks, we make a use of semaphore. There are various kinds of semaphores viz. Binary Semaphore, Counting Semaphore and POSIX.

  1. Binary Semaphore:
    The semaphore over here has two states i.e. '0' and '1'. When the semaphore and in turn the resource is available, the semaphore bit is '0'. Whenever a task acquires the semaphore, it makes the bit '1' so that the other tasks trying to access the semaphore, will find it to be unavailable. This is shown in the figure below for example of two tasks 'A' and 'B

  2. Counting Semaphore:
    This is used in cases where multiple tasks can access the resource simultaneously. For example, a car parking lot has multiple cars that can be parked in it. The counting semaphore can be initialised to the maximum number of cars that can be parked, when no cars are there in the parking lot. Now whenever a car enters the parking lot the counter should decrement and whenever a car leaves the parking lot, the counter should increment. When the count is zero, it indicates that no further cars can be parked in the lot. The cars can be replaced with task and the parking lot with the resource that is to be shared in the embedded system for multiple tasks.

  3. MUTEX (Mutual Exclusion):
    In case if a resource or a semaphore is required by a task, and it gets the access of the same. It calls another task which also requires the same resource, will now get stuck as it is already acquired by the previous task. This is called as mutual exclusion. To resolve this a special type of semaphore called as MUTEX is used. In this case there is an additional information specifying that the semaphore is acquired by one main task and another counter keeps on incrementing, when a subtask uses it. When a subtask completes the use of the resource and decrements the count, it doesn't releases the semaphore if the count is not zero.

Please log in to add an answer.