SEP400 - Lab 7: Semaphores with Shared Memory

Due: Sunday, March 23, 2025

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:
start.sh,
client.h,
client1.cpp,
client2.cpp,
client3.cpp,
Makefile.

This code contains everything except the creation of shared memory and synchronization. It is your task to implement shared memory and 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.

NB: Please insert a sleep of 1 second in the for-next loop for each client, so we can see communication between them.

Lab Submission:

Please mail your client.h, client1.cpp, client2.cpp and client3.cpp to: miguel.watler@senecapolytechnic.ca

NB: My last name is Watler, not Walter.

Late Policy

You will be docked 10% if your lab is submitted 1-2 days late.
You will be docked 20% if your lab is submitted 3-4 days late.
You will be docked 30% if your lab is submitted 5-6 days late.
You will be docked 40% if your lab is submitted 7-8 days late.
You will be docked 100% if your lab is submitted over 8 days late.