100% found this document useful (1 vote)
183 views

CHAP-5 Task - Communication

The document discusses task communication and synchronization in embedded systems. It covers various methods for tasks to communicate, including shared memory, message passing, and remote procedure calls. Shared memory allows tasks to directly access and modify the same memory locations to exchange data. Message passing involves tasks posting messages to queues for other tasks to receive asynchronously. Remote procedure calls and sockets allow tasks on different systems to communicate. The document also discusses how tasks can synchronize their execution using various task synchronization methods.

Uploaded by

eyohamehari235
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
183 views

CHAP-5 Task - Communication

The document discusses task communication and synchronization in embedded systems. It covers various methods for tasks to communicate, including shared memory, message passing, and remote procedure calls. Shared memory allows tasks to directly access and modify the same memory locations to exchange data. Message passing involves tasks posting messages to queues for other tasks to receive asynchronously. Remote procedure calls and sockets allow tasks on different systems to communicate. The document also discusses how tasks can synchronize their execution using various task synchronization methods.

Uploaded by

eyohamehari235
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Task Communication Task Synchronization

Introduction to Embedded System


(CSE 507)

Prepared By: Awet Kidane


([email protected])

Mekelle Institute of Technology


Department of Electronics and Communication Engineering

December 28, 2023

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 1 / 33
Task Communication Task Synchronization

Chapter Outline

1 Task Communication

2 Task Synchronization

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 2 / 33
Task Communication Task Synchronization

Chapter Outline

1 Task Communication

2 Task Synchronization

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 3 / 33
Task Communication Task Synchronization

Outline:

Task Communication
Shared Memory
Message Passing
Remote Procedure Call (RPC) and Socket

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 4 / 33
Task Communication Task Synchronization

Task Communication

In a multitasking system, multiple tasks/ processes run concurrently (in


pseudo parallelism) and each process may or may not interact between.
Based on the degree of interaction, the processes/ tasks running on an OS
are classified as:

Co-operating Processes: In the co-operating interaction model, one pro-


cess requires the inputs from other processes to complete its execution.
Competing Processes: The competing processes do not share anything
among themselves but they share the system resources. The competing
processes compete for the system resources such as file, display device, etc.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 5 / 33
Task Communication Task Synchronization

Cont’d ...

The co-operating processes exchanges information and communicate through


the following methods:

1 Co-operation through sharing: Exchange data through some shared re-


sources.
2 Co-operation through Communication: No data is shared between the pro-
cesses. But they communicate for execution synchronization.

The mechanism through which tasks/ processes communicate each other


is known as Inter Process/ Task Communication (IPC). IPC is essential
for process co-ordination. The various types of IPC mechanisms adopted
by process are kernel (Operating System) dependent. They are explained
below.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 6 / 33
Task Communication Task Synchronization

Shared Memory

Processes share some area of the memory to communicate among them.


Information to be communicated by the process is written to the shared
memory area. Processes which require this information can read the same
from the shared memory area.

The implementation of shared memory is kernel dependent. Different


mechanisms are adopted by different kernels for implementing this, a few
among them are:

1 Pipes
2 Memory Mapped Objects

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 7 / 33
Task Communication Task Synchronization

Cont’d ...
1 Pipes:
Pipes follow the client-server architecture.
A process which creates a pipe is known as pipe server and a process which
connects to a pipe is known as pipe client.
A pipe can be considered as a medium for information flow and has two
conceptual ends. It can be unidirectional, allowing information flow in one
direction or bidirectional allowing bi-directional information flow.
A unidirectional pipe allows the process connecting at one end of the pipe
to write to the pipe and the process connected at the other end of the pipe to
read the data, whereas a bi-directional pipe allows both reading and writing
at one end. The unidirectional pipe can be visualized as

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 8 / 33
Task Communication Task Synchronization

Cont’d ...

The implementation of “Pipes”is OS dependent. Microsoft® Windows


Desktop Operating Systems support two types of “Pipes” for Inter Process
Communication. Namely;
1 Anonymous Pipes: The anonymous pipes are unnamed, unidirectional
pipes used for data transfer between two processes. Eg. Pipe()
2 Named Pipes: Named pipe is a named, unidirectional or bi-directional pipe
for data exchange between processes. Like anonymous pipes,
the process which creates the named pipe is known as pipe server.
A process which connects to the named pipe is known as pipe client.
With named pipes, any process can act as both client and server allowing
point-to-point communication. Named pipes can be used for communicating
between processes running on the same machine or between processes running
on different machines connected to a network.
E.g mkfifo()

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 9 / 33
Task Communication Task Synchronization

Cont’d ...

1 Memory Mapped Objects:


Memory mapped object is a shared memory technique adopted by certain
Real Time Operating Systems for allocating a shared block of memory
which can be accessed by multiple process simultaneously.

In this approach, a mapping object is created and physical storage for it is


reserved and committed. A process can map the entire committed physical
area or a block of it to its virtual address space. All read and write operation
to this virtual address space by a process is directed to its committed physical
area. Any process which wants to share data with other processes can map
the physical memory area of the mapped object to its virtual memory space
and use it for sharing the data. The concept of memory mapped object is
shown bellow.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 10 / 33
Task Communication Task Synchronization

Cont’d ...

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 11 / 33
Task Communication Task Synchronization

Message Passing

Message passing is a/ an synchronous/ asynchronous information exchange


mechanism for Inter Process/ Thread Communication. The major differ-
ence between shared memory and message passing technique is:
1 Through shared memory lots of data can be shared whereas only limited
amount of info/ data is passed through message passing.
2 Message passing is relatively fast and free from the synchronization over-
heads compared to shared memory.
Based on the message passing operation between the processes, message
passing is classified into:
1 Message Queues
2 Mailbox
3 Signaling

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 12 / 33
Task Communication Task Synchronization

Cont’d ...

1 Message Queues:
Process which wants to talk to another process posts the message to a
First-In-First-Out (FIFO) queue called “Message queue”, which stores the
messages temporarily in a system defined memory object, to pass it to the
desired process.

The implementation of the message queue, send and receive methods are
OS kernel dependent. Eg.msgget(),msgsnd(),msgrcv().

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 13 / 33
Task Communication Task Synchronization

Cont’d...
1 Mailbox:
Mailbox is a special implementation of message queue.
Usually used for one way communication,
Only a single message is exchanged through mailbox whereas “message
queue” can be used for exchanging multiple messages. One task/process
creates the mailbox and other tasks/process can subscribe to this mailbox
for getting message notification.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 14 / 33
Task Communication Task Synchronization

Cont’d ...

1 Signaling:
Signals are used for an asynchronous notification mechanism. The signal
mainly used for the execution synchronization of tasks process/ tasks.
Signals do not carry any data and are not queued.
The implementation of signals is OS kernel dependent and VxWorks RTOS
kernel implements “signals” for inter process communication.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 15 / 33
Task Communication Task Synchronization

RPC and Socket

Remote Procedure Call is the Inter Process Communication (IPC) mecha-


nism used by a process, to call a procedure of another process running on
the same CPU or on a different CPU which is interconnected in a network.

In the object oriented language terminology, RPC is also known as Re-


mote Invocation or Remote Method Invocation (RMI). The CPU/ process
containing the procedure which needs to be invoked remotely is known
as server. The CPU/ process which initiates an RPC request is known as
client.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 16 / 33
Task Communication Task Synchronization

Cont’d ...

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 17 / 33
Task Communication Task Synchronization

Cont’d...

Socket:
Sockets are used for RPC communication.
Socket is a logical endpoint in a two-way communication link between two
applications running on a network.
A port number is associated with a socket so that the network layer of the
communication channel can deliver the data to the designated application.
Sockets are of different types namely; Internet sockets (INET), UNIX sock-
ets, etc.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 18 / 33
Task Communication Task Synchronization

Chapter Outline

1 Task Communication

2 Task Synchronization

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 19 / 33
Task Communication Task Synchronization

Outline:

Task Synchronization
Task Communication/Synchronization Issues
Conditions Favoring Deadlock
Task Synchronization Techniques

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 20 / 33
Task Communication Task Synchronization

Task Synchronization

In a multitasking environment, multiple processes run concurrently and


share the system resources. Also, each process may communicate with
each other with different IPC mechanisms.
There may be situations that; two processes try to access a shared memory
area, where one process tries to write to the memory location when the
other process is trying to read from the same memory location. This will
lead to unexpected results.
The solution is, make each process aware of access of a shared resource.
The act of making the processes aware of the access of shared resources
by each process to avoid conflicts is known as “Task/ Process Synchro-
nization”.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 21 / 33
Task Communication Task Synchronization

Cont’d ...

Task/ Process Synchronization is essential for:


1 Avoiding conflicts in resource access (racing, deadlock, etc.) in multitasking
environment.
2 Ensuring proper sequence of operation across processes.
3 Establish proper communication between processes.

The code memory area which holds the program instructions (piece of
code) for accessing a shared resource is known as “Critical Section”. In
order to synchronize the access to shared resources, the access to the
critical section should be exclusive.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 22 / 33
Task Communication Task Synchronization

Cont’d...

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 23 / 33
Task Communication Task Synchronization

Task Communication/synchronization Issues

Various synchronization issues may arise in a multitasking environment,


if processes are not synchronized properly in shared resource access, such
as:
Racing or Race Condition: is the situation in which multiple processes
compete (race) each other to access and manipulate shared data concurrently.
In a race condition the final value of the sheared data depends on the process
which acted on the data finally.

Deadlock: is the condition in which a process is waiting for a resource


held by another process which is waiting for a resource held by the first
process; hence, none of the processes are able to make any progress in their
execution.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 24 / 33
Task Communication Task Synchronization

Cont’d ...

To elaborate: Process A holds a resource ”x” and it wants a resource


y held by Process B. Process B is currently holding resource ”y” and it
wants the resource ”x” which is currentlyheld by Process A. Both hold the
respective resources and they compete each other to get the resource held
by the respective processes. The result of the competition is deadlock.
None of the competing process will be able to access the resources held
by other processes since they are locked by the respective processes (If
a mutual exclusion policy is implemented for shared resource access, the
resource is locked by the process which is currently accessing it.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 25 / 33
Task Communication Task Synchronization

Cont’d ...

Livelock: The Livelock condition is similar to the deadlock condition


except that a process in Lovelock condition changes its state with time.
While in deadlock a process enters in wait state for a resource and continues
in that state forever without making any progress in the execution, in a
livelock condition a process always does something but is unable to make
any progress in the execution completion.
Starvation: In the multitasking context, starvation is the condition in
which a process does not get the resources required to continue its execu-
tion for a long time. As time progresses the process starves on resource.
Starvation may arise due to various conditions like by product of preven-
tive measures of deadlock, scheduling policies favoring high priority tasks
and tasks with shortest execution time, etc.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 26 / 33
Task Communication Task Synchronization

Conditions Favoring Deadlock (Coffman conditions)

Deadlock is a result of the combined occurrence of these four conditions


listed below.
Mutual Exclusion: The criteria that only one process can hold a resource
at a time. Meaning processes should access shared resources with mutual
exclusion. Typical example is the accessing of display hardware in an
embedded device.
Hold and Wait: The condition in which a process holds a shared resource
by acquiring the lock controlling the shared access and waiting for additional
resources held by other processes.
No Resource Pre-emption: The criteria that operating system cannot take
back a resource from a process which is currently holding it and the resource
can only be released voluntarily by the process holding it.
Circular Wait: A process is waiting for a resource which is currently held
by another process which in turn is waiting for a resource held by the first
process.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 27 / 33
Task Communication Task Synchronization

Task Synchronization Techniques

The technique used for task synchronization in a multitasking environment


is mutual exclusion.
Semaphore: is a sleep and wakeup based mutual exclusion implemen-
tation for shared resource access. Semaphore is a system resource; and
a process which wants to access the sharedresource can first acquire this
system object to indicate the other processes which wants theshared re-
source that the shared resource is currently in use by it.
The resources which are shared among a process can be either for exclusive
use by a process or for using by a number of processes at a time.
The display device of an embedded system is a typical example of a shared
resource which needs exclusive access by a process.
Based on the implementation, Semaphores can be classified into Binary
Semaphore and Counting Semaphore.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 28 / 33
Task Communication Task Synchronization

Cont’d...

Synchronization tool that provides more sophisticated ways for process to


synchronize their activities.
Semaphore S – integer variable, which can only be accessed via two
indivisible (atomic) operations

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 29 / 33
Task Communication Task Synchronization

Cont’d ...

Binary Semaphore: Implements exclusive access to shared resource by


allocating the resource to a single process at a time and not allowing the
other processes to access itwhen it is being used by a process.

“Only one process/ thread” can own the binary semaphore at a time.
The state of a “binary semaphore” object is set to signaled when it is not
ownedby any process/ thread, and set to non-signaled when it is owned by
any process/thread.
The implementation of binary semaphore is OS kernel dependent. Under
certain OS kernel it is referred as mutex.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 30 / 33
Task Communication Task Synchronization

Cont’d...

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 31 / 33
Task Communication Task Synchronization

Cont’d ...

Counting Semaphore: Maintains a count between zero and a maximum


value. It limits the usage of resource by a fixed number of processes/
threads.
The count associated with a “Semaphore object” is decremented by one
when a process/thread acquires it and the count is incremented by one when
a process/ thread releases the“Semaphore object”.
The state of the counting semaphore object is set to “signaled” when the
count of the object is greater than zero.
The state of the “Semaphore object” is set to non-signaled when the
semaphore is acquired by the maximum number of processes/ threads
that the semaphore can support(i.e. when the count associated with the
“Semaphore object” becomes zero).
The creation and usage of “counting semaphore object” is OS kernel de-
pendent.

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 32 / 33
Task Communication Task Synchronization

Cont’d...

By: Awet Kidane (MSc) Introduction to Embedded System Mekelle Institute of Technology 33 / 33

You might also like