Starting from:

$25

CPEN333 - Software Systems Engineering - Lab 4 - Solved

This lab introduces the student to concepts of inter-process communication. That is, how to establish communication between processes and threads in a distributed/concurrent application

 

Introduction

Before tackling these questions, make sure you have downloaded and expanded (in the correct directory) the zip file from the web-site relating to the “compressed RTExamples”. 

 

Also make sure you are familiar with the Visual C++ environment and know how to create projects, build, execute and run them. There is a handout on the web-site showing you how to create Concurrent Applications using Visual C++.

 

Part A   - 30%

Workspace Q3 demonstrates inter-process communication using a datapool. 
Q3 is the parent process and Q4 the child. Make sure you build both projects before running Q3. See if you can figure out what is happening within the two projects and discover how they communicate across a process boundary using a datapool.



1.       Modify the program to store data of your own. For this you can include things like name, age, address etc (I’ll leave it up to you what to include) into the datapool and make sure the child program (Q4) is modified to read the data correctly. (Hint: modify the structure ‘mydatapooldata’ in both parent and child programs to incorporate the data you want to communicate. Both must describe exactly the same data and layout)

 

Finally, see if you can create a further child process to share the data, i.e. one process writing data into the pool, while two other child processes read it out. 

 

2.       Workspace Q7 is similar to Q3/Q4 but uses a pipeline instead of a data pool to achieve inter-process communication. 

 

·         Add a second pipeline to the parent program and write the same data into it as the 1st pipeline. 

·         Now introduce a 2nd child process and get it to read out and display the data in the 2nd pipeline concurrently with the 1st child program reading from the 1st pipeline. 

 

 

 

Questions to think about 

                                                   i.      Think about why this is not as efficient as using a data pool when the number of child processes wishing to read the same data is large?  Why is it not possible for several child processes to share the same pipeline for reading purposes?

                                                 ii.      By default, the size of a pipeline is 1024 bytes in size, what would happen if a process wrote more than this amount of data into the pipeline without a process removing some of the data? Verify this for yourself by modifying the program and observe the effect.

 

Part B    - 30%

·         Create your own new project with 1 parent process and 2 child processes.

·         Declare 2 structures (with more than one variable in each) representing the data that will be communicated between parent and child processes, one structure per child (the structures should all contain different data). 

·         Get the Parent process to create and open 2 individual typed pipelines (based on the structures) and then have the parent create the 2 child processes to run concurrently with it.

·         Inside each of the 2 child processes, write code to open the typed pipelines created by the parent and, as part of an infinite loop, get them to write corresponding data into their respective pipelines. Using varying time delays in each of the child process loops (e.g. use the SLEEP() function)

·         Next, get the parent, to read and display the data written into the 2 pipelines by the 2 child processes. The parent should use a multi-threaded solution where the parent creates 2 child threads (within the parent process) to read from the 2 pipelines (without polling).

 

 

Part C - Local Sockets and Remote Procedure Calls - 40%

 

We talked in class about the concept of “Sockets” and remote procedure calls (RPC) as a means of inter-process communication for distributed system. For this part of the lab, you will have to do some research into writing “sockets” code under windows (using Winsock related library). Look on-line there are plenty of tutorials around to get you started. 

 

Regardless, create a new project/solution in visual studio that includes a parent (which will act as the client) and a 1 child process (the server). Both parent and child should attempt to use sockets in some creative way so that the parent/client can send a command to the child/server along with parameters that represent some action to be performed. 

 

The child will carry out the action and return back to the parent (again via sockets) an appropriate response/result. The exact commands/action are left to you to invent, they don’t have to be complex, as it’s the concept we are interested in, but aim for at least 3 different commands/actions.

 

The main intention of sockets was distributed (i.e. machine to machine communication), but it can just as easily be used as a form of inter-process communication between processes in the same machine 
(using a local host IP address – see here https://whatismyipaddress.com/localhost ) 
so implement that for this part of the lab 

 Part D   -

·         Build on your 1st assignment by adding the code to create DataPools and/or Pipelines to your assignments as shown in your assignment.

·         Build Test code into each process/active object to prove that it can write and read to the relevant Datapools/pipelines. 

More products