1. Task Communication and Synchronization
Task Communications- Page 1
EEC682– Spring 2025
Inter-task communication is an important service that must be
provided by any real-time kernel. This communication is needed
to:
2. Inter-task communication is an important service that must be
provided by any real-time kernel. This communication is needed
to:
Task Communication and Synchronization
Task Communications- Page 1
EEC682– Spring 2025
exchange data between tasks.
avoid problems resulting from access to common resources.
satisfy task precedence constraints.
3. Inter-task communication is an important service that must be
provided by any real-time kernel. This communication is needed
to:
Some communication mechanisms, such as semaphores, require
a shared memory among tasks. The method of message passing
is more general.
Task Communication and Synchronization
Task Communications- Page 1
EEC682– Spring 2025
exchange data between tasks.
avoid problems resulting from access to common resources.
satisfy task precedence constraints.
4. Message queues and mailboxes
Task Communications- Page 2
EEC682– Spring 2025
5. A minimum set of system calls that handle message passing is the
following:
send (destination, &message)
receive (source, &message)
Message queues and mailboxes
Task Communications- Page 2
EEC682– Spring 2025
6. A minimum set of system calls that handle message passing is the
following:
send (destination, &message)
receive (source, &message)
Message queues and mailboxes
A message sent but not yet received is queued by the system.
Queue will have a pre-specified maximum capacity.
Task Communications- Page 2
EEC682– Spring 2025
7. A minimum set of system calls that handle message passing is the
following:
send (destination, &message)
receive (source, &message)
Many design options exist for the message format, addressing
methods, synchronization modes, and queuing discipline. All
these can affect program timing.
Message queues and mailboxes
A message sent but not yet received is queued by the system.
Queue will have a pre-specified maximum capacity.
Task Communications- Page 2
EEC682– Spring 2025
8. Message Format
Typically, message is a sequence of bytes with fixed or variable
length. Correct interpretation of message content is the
responsibility of the communicating tasks, not the operating
system.
Message queues and mailboxes
Task Communications- Page 3
EEC682– Spring 2025
9. Message Format
Message queues and mailboxes
Task Communications- Page 3
EEC682– Spring 2025
Typically, message is a sequence of bytes with fixed or variable
length. Correct interpretation of message content is the
responsibility of the communicating tasks, not the operating
system.
10. Addressing Method
Direct addressing: using task id.
Allows only one-to-one communication.
Message Format
Typically, message is a sequence of bytes with fixed or variable
length. Correct interpretation of message content is the
responsibility of the communicating tasks, not the operating
system.
Message queues and mailboxes
Task Communications- Page 3
EEC682– Spring 2025
11. Addressing Method
Direct addressing: using task id.
Allows only one-to-one communication.
Indirect addressing : using mailboxes
Allows many-to-one, one-to-many or many-to-many modes.
Message Format
Typically, message is a sequence of bytes with fixed or variable
length. Correct interpretation of message content is the
responsibility of the communicating tasks, not the operating
system.
Message queues and mailboxes
Task Communications- Page 3
EEC682– Spring 2025
13. If no message is available, the receiver will typically be blocked
until one arrives. Alternatively, it can return immediately with
an error code.
Task Communications- Page 7
EEC682– Spring 2025
14. Example (1): Mutual exclusion using messages
Message queues and mailboxes
Using messages, how to control access to resource (e.g. data)
that cannot be accessed by more than one task at the same time
Task Communications- Page 5
EEC682– Spring 2025
15. Example (1): Mutual exclusion using messages
To access resource, any task will use the following sequence:
receive(Access_box,&msg);
Access_resource;
send(Access_box,&msg);
Message queues and mailboxes
Using messages, how to control access to resource (e.g. data)
that cannot be accessed by more than one task at the same time
Task Communications- Page 5
EEC682– Spring 2025
16. Example (2): Bounded buffer problem
A buffer of size n with reader and writer tasks running at
different speeds.
Message queues and mailboxes
Task Communications- Page 6
EEC682– Spring 2025
17. Example (2): Bounded buffer problem
A buffer of size n with reader and writer tasks running at
different speeds.
Message queues and mailboxes
Task Communications- Page 6
EEC682– Spring 2025
buffer
writer Reader
18. Example (2): Bounded buffer problem
A buffer of size n with reader and writer tasks running at
different speeds.
Message queues and mailboxes
Task Communications- Page 6
EEC682– Spring 2025
Reader task
send(writer,’empty’);
receive(writer,’full’);
Read_data_item;
19. Example (2): Bounded buffer problem
A buffer of size n with reader and writer tasks running at
different speeds.
Message queues and mailboxes
Task Communications- Page 6
EEC682– Spring 2025
Reader task
receive(reader,’empty’);
send(writer,’empty’);
receive(writer,’full’);
Read_data_item;
Writer task
Write_data_item;
send(reader,’full’);
20. in asynchronous send, sender will continue operation
regardless of whether the message was received or not.
Message Synchronization Modes
If no message is available, the receiver will typically be blocked
until one arrives. Alternatively, it can return immediately with
an error code.
Sender can operate in one of two modes:
Task Communications- Page 7
EEC682– Spring 2025
21. in asynchronous send, sender will continue operation
regardless of whether the message was received or not.
In synchronous send, the sender will be blocked until it
receives an acknowledgment from the receiver.
Message Synchronization Modes
If no message is available, the receiver will typically be blocked
until one arrives. Alternatively, it can return immediately with
an error code.
Sender can operate in one of two modes:
Task Communications- Page 7
EEC682– Spring 2025
22. in asynchronous send, sender will continue operation
regardless of whether the message was received or not.
Message Synchronization Modes
If no message is available, the receiver will typically be blocked
until one arrives. Alternatively, it can return immediately with
an error code.
Sender can operate in one of two modes:
Task Communications- Page 7
EEC682– Spring 2025
In synchronous send, the sender will be blocked until it
receives an acknowledgment from the receiver.