Week 13 - August 5-9
Introduction
This week we will look at the last method of inter-process communications - shared memory.
Shared memory is different from the others stored because it is primarily a hardware-based form of
inter-process communications. It is faster than the other methods studied, but it is also
the most primitive form of interprocess communication.
We will also have a final exam review.
Videos
Quiz
Final Assessment
Lecture Material
Labs
- Lab 9 - Server with Multiple Clients and a Receive Thread with Mutexing.
- Lab 10 - Semaphores with Shared Memory.
Assignment(s)
Assignment 2.
Sample Code
Shared Memory
- Code that demonstrates shared memory via Linux utilities can be found in
client.h,
client1.cpp and
client2.cpp with its
Makefile.
- Code that demonstrates shared memory via a memory pool can be found in
client.h,
client1.cpp and
client2.cpp with its
Makefile.
This will give a segmentation fault. The address of the memory pool of client1
has been passed to client2, therefore it should be possible to read the contents
of the memory pool in client2. However, each process has its own virtual address
space, so the address passed by client1 will not be the same address when read
by client2. THIS DOES NOT WORK.
Linux has its own shared memory utilities. It is better to use those.
- Code for two processes which send messages to each other via shared memory can be found at:
client.h,
client1.cpp and
client2.cpp with its
Makefile.
The messages passed back and forth between the clients have been taken from the Monty Python
skit: The Funniest Joke.
- Code that simulates 16 clients trying to write to a radio with four channels can be found at:
client.h,
client.cpp,
memoryManager.cpp and
Makefile.
The memory map can be seen at:
RadioChannelsMemoryMap.docx.
Scripts for starting and stopping the simulation can be found at:
start.sh and
stop.sh.
Each channel uses a part of shared memory. The clients write to one of the channels by writing into the channel's shared memory.
The use of semaphores ensures that the number of clients writing to the radio's channels is limited to four.