Exercise 1 Completing the Linux skeleton of the OO OS Api
This is the files we have wrote:
Mutex.hpp
Mutex.cpp
Thread.cpp
We now make the OS API with the command 'make DEBUG=1 TARET=host all' :
To validate the OS API we are making use of the test folder which contains a .cpp file for testing threads. In this case we are testing Threads.cpp. Because the TestThreads.cpp inherits ThreadFunctor which make use of both Mutex for locking and broadcast. In this case we are also testing our Threadfunctor which include Completion that have both Mutex and Conditional.
TestThreads.cpp
Testing with TestThread.cpp
Questions to answer:
- Inspecting the OSApi library, describe the chosen setup and how it works.
The folder 'Common' contains all the files, that are used in every OS. The 'inc' folder contains all the header-files for the different OS. The platform folders contain the different source files for the platform. When we make, the makefile choose which hpp- and cpp-files to be used.
- A thread function is a free C function, how is the connection made such that our desired run() method is called.
The connection is made in the threadMapper form the class ThreadFunctor.
- In the windows implementation the so-called pimpl/cheshire cat idiom is used. Explain how it is used and what is achieved in this particular situation.
Private data in a class is instead placed in a struct which is implemented in a source file. To gain access to the data you would refer to the struct by a smart pointer. This way implementation is hidden from the user and makes compiling time faster as change of private data is not in the private of a class but implemented in an implementation file.
- Why is the class Conditional a friend to class Mutex? What does it mean to be a friend?
The Conditional class have to get and use the private attribut 'mut_' from the Mutex class. The only way this can happen, is if the Conditional class is a friend of the Mutex Class.
Exercise 2 On target
We compile for the target with arm-angstrom compiler:
Questions to answer:
- Did you do need to change code for this to work, if so what?
Exercise 3 PCLS now the OS Api
Same implementation style from TestThread.cpp has been used, to work with our PCLS.
class CarThread
Which changes did you make and why?
As mentioned in the exercise review, the implementation of the threads functions had to be implemented in run method which inherits threadFunctor. Therefore our implementation needed the namespace osapi:: in order to work with our OSAPI.
Does this modification whereby you utilize the OSApi library improve your program or not. Substantiate you answer with reasoning.
In our exercise we had not utilized our API design other than testing with linux OS. However the design behind making APIs makes implementation much easier for compiling on other OS system.
Exercise 1:
SvarSletIn this exercise you have to write the missing or uncompleted files in the OSAPI.
This will show that you have an understanding of the use of the different files in the OSAPI.
You do this to perfection and also test your Thread.cpp with the TestThreads.cpp, which is good, since this will test both Threadfunctor, Mutex and Conditional.
Your answers on the questions is all correct.
Exercise 2:
A simple task, and you explained why in the answer of the question. Good job.
Exercise 3:
In this exercise you have to show that you can implement the OSAPI in the parkinglot system.
This will show that you have understood the functions of the OSAPI and it will optimize the program for multiple operation systems.
You did a good job in completing this task and explained the limits for your doing in the questions afterward.
Good job. Exercise is accepted.
Reviewed by Anders Faurholdt, Kristian Ørts & Jonas Harder