![]() |
|
Home | UNX511 | Help Notes | Contact |
FIRST: See labs.html for information on labs.
You may wish to consult our class materials and sample code. For the code to go with this lab, see https://github.com/jsellens/unx511_samples/tree/main/lab_10
Three processes are going to communicate with each other through shared memory. The memory is allocated as follows:
struct Memory {
int packet_no;
unsigned short srcClientNo;
unsigned short destClientNo;
char message[BUF_LEN];
};
Each client is numbered 1, 2, and 3. Each client will read from the shared memory looking for a message for itself. If the destClientNo matches the client's number, it will print out the message and then send a message to another client.
For example, if client 2 receives a message from client 1, the message could read as:
Client 2 has received a message from client 1:
This is message 29 from client 1
Client 2 will then send a message to either client 1 or 3. For example, if client 2 sends a message to client3, the message could read as:
Client 3 has received a message from client 2:
This is message 28 from client 2
Since three clients will be accessing shared memory, some sort of synchronization mechanism is required.
Code has been given for clients 1, 2 and 3, plus its Makefile. A start.sh has also been provided to start all processes. They can be found at:
https://github.com/jsellens/unx511_samples/tree/main/lab_10
This code contains everything except synchronization. It is your task to implement a synchronization mechanism for these three clients, such that only one accesses shared memory at a time. Clients 1 and 2 should wait for client 3 to start up. You will need to modify client.h, client1.cpp, client2.cpp and client3.cpp.
Note: Please insert a sleep of 1 second in the for-next loop for each client, so we can see communication between them.