CSE 532S Wrapper Facade Studio

Please complete the required studio exercises listed below, along with any of the (optional) enrichment exercises that interest you.

As you work through the exercises, please record your answers in a file, and upon completion please upload a file with your answers to the assignment page for this studio in Canvas.

Please make sure that the name of each person who worked on these exercises is listed in the first answer, and that you number your answers so they are easy for us to match up with the appropriate exercise.


    Required Exercises

  1. As the answer to the first exercise, list the names of the people who worked together on this studio.

  2. We will use g++ on the CEC Linux Lab machines for all the studios and labs in this course (though you also are strongly encouraged to use Visual Studio in the Urbauer 216 and 215 labs, especially as needed to debug tricky multi-threaded programming issues that may arise). The labs will be graded using the gcc 8.3.0 version, so you should first make sure that you have that version installed.

    To do that, please first ssh into shell.cec.wustl.edu using your WUSTL Key id and password and then run the command qlogin -q all.q which will let you log into a dedicated Linux host.

    Then, run the command module add gcc-8.3.0 to add gcc 8.3.0 to your environment, and please also add that line to to the .bashrc file in your home directory so that the next time you log in it'll be there too (if you run a different shell than bash, please edit the configuration file for it instead). As the answer to this exercise, show the output from running the command which g++ on one of the Linux Lab machines, and make sure it gives the right version.

  3. Create a new empty directory for this studio (for example named something like wrapper_facade).

    In that directory, edit a new C++ source code file (which should be named something like wrapper_facade.cpp) and in it write a main function whose signature looks like the standard (i.e., portable between Linux and Windows) shell (on Windows, terminal window) program main function entry point for C++: int main (int, char * []). Please also use the #define precompiler directive to define a manifest constant whose value is 0, and have the main function simply return that constant to indicate successful completion of the program.

    Make sure the code compiles using g++ with the -Wall (to generate all possible compiler warnings) and -std=c++11 (to enforce the C++11 standard) and -pthread (to give access to the pthreads library) compiler switches, and that you can run the program. As the answer to this exercise, please give the full path to the directory in which the executable program was created (and was run).

  4. In that same file, write a function that takes no arguments and prints out a single line message to the standard output stream, and call that function from your program's main function (hint: for this exercise and the ones that follow, please use endl to both end the line and flush the stream). Build and run your program, and as the answer to this exercise please show the output the program produced.

  5. Modify your program's main function so that instead of calling the function directly it creates a separate thread with that function as the thread's entry point, and then joins with that thread (as shown in Williams Section 1.4.1). Build and run your program, and please confirm that the output it produces is the same as it produced for the previous exercise. As the answer to this exercise please show the code itself.

  6. Modify your program's main function so that instead of running the function in a single thread it creates multiple threads each running that same function, and then joins with each of them. Build and run your program, and as the answer to this exercise please show the code and the output your program produced.

    Enrichment Exercise (Optional)

  7. Modify your main function's signature to include variable names (e.g., int main (int argc, char * argv[])) and then repeat any of the previous exercises where the function printed out a message, but this time pass the main function's command line arguments into the function, either directly from the main function or through the thread constructor, depending on the exercise. As the answer(s) to this exercise, please show both the code you wrote and the output the program produced when you compiled and ran it.