








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Various concurrent programming concepts using message passing and semaphores in java and c++. It includes classes for channels, mailboxes, bounded buffers, and rendezvous, as well as examples of their implementation and usage. The document also discusses the rendezvous concept in client-server environments and provides a java class for managing client requests and server replies.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









5. Message-Passing
Threads can communicate and synchronize by sending and receiving messages acrosschannels.A channel is an abstraction of a communication path between threads:^
If shared memory is available, channels can be implemented as objects that are sharedby threads.
Without shared memory, channels can be implemented using kernel routines thattransport messages across a communication network (Chapter 6) Outline:^
Basic message passing using send and receive commands.
Rendezvous.
Testing and debugging message-passing programs. 5.1 Channel Objects Threads running in the same program (or process) can access channel objects in sharedmemory.
channel requestChannel = new channel();channel replyChannel = new channel();
Thread
Thread
requestChannel.send(request);
request = requestChannel.receive();
reply = replyChannel.receive();
replyChannel.send(reply);
A thread that calls
send()
or
receive()
may be blocked. Thus, send and receive operations
are used both for communication and synchronization.
Types of send and receive operations:^
blocking send: the sender is blocked until the message is received (by a
receive()
operation).
buffer-blocking send: messages are queued in a bounded message buffer, and thesender is blocked only if the buffer is full.
non-blocking send: messages are queued in an unbounded message buffer, and thesender is never blocked.
blocking receive: the receiver is blocked until a message is available.
non-blocking receive: the receiver is never blocked. A receive command returns anindication of whether or not a message was received. Asynchronous message passing
: blocking receive operations are used with either non-
blocking or buffer-blocking send operations.S
ynchronous message passing:
The send and receive operations are both blocking.
Either the sender or the receiver thread will be blocked, whichever one executes itsoperation first.
Can be simulated using asynchronous message passing: the sender can issue a buffer-blocking send followed immediately by a blocking receive.
5.1.1 Channel Objects in Java Threads in the same Java Virtual Machine (JVM) can communicate and synchronize bypassing messages through user-defined
channels
that are implemented as shared objects.
public abstract class channel {
public abstract void send(Object m); // send a message objectpublic abstract void send();
// acts as a signal to the receiver
public abstract Object receive();
// receive an object.
Three types of channels:^
mailbox
: many senders and many receivers may access a mailbox object