Skip to main content
Engineering LibreTexts

19.3: Exercises

  • Page ID
    19983
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Below are some quiz questions and suggested projects based on this chapter.

    Quiz Questions

    Below are some quiz questions based on this chapter.

    1) Explain the difference between concurrency and parallel processing.

    2) Name the two common approaches to parallel computations.

    3) In distributed processing, where might the parallel computations take place?

    4) Provide the names of two examples of large distributed computing projects. Include a one-sentence description of each.

    5) In multiprocessing, where might the parallel computations take place?

    6) Provide one advantage and one disadvantage of the distributed computing approach to parallel processing.

    7) Provide one advantage and one disadvantage of the multiprocessing approach to parallel processing.

    8) Explain what a race condition is.

    9) Will a race condition occur when a shared variable is read by multiple simultaneously executing threads? Explain why or why not.

    10) Will a race condition occur when a shared variable is written by multiple simultaneously executing threads (without any coordination)? Explain why or why not.

    Suggested Projects

    Below are some suggested projects based on this chapter.

    1) Implement the outlined example program and create two thread functions where each thread function computes the formula MAX/2 times. Set MAX to 1,000,000,000 (one billion).

    1. Initially, structure the main function to call the first thread function and wait until it completes until creating the second thread function and waiting until it completes. This will force the threads to execute sequentially (not in parallel). Include a function to convert the integer into a string and display the result to the console. Use the debugger as necessary to debug the program. When working, execute the program without the debugger and verify that the displayed results are the same as MAX.

    2. Use the Unix time(For more information, refer to: http://en.Wikipedia.org/wiki/Time_(Unix)) command to establish a base execute time. Record the total elapsed time.

    3. Restructure the program so that both threads are created and then waiting for both to complete. This will allow the execution of the threads to occur in parallel. Use the debugger as necessary to debug the program. When working, execute the program without the debugger and note the final value of MAX. Ensure a full understanding of why the displayed value for MAX is incorrect. Additionally, use the Unix time command on the modified program to verify that it uses less elapsed time.

    2) Update the program from the previous question to resolve the race condition. Use the debugger as necessary to debug the program. One very simple way to accomplish this is to use temporary variables for each thread and combine them after both thread functions have completed and display the final combined result. When working, execute the program without the debugger and verify that the displayed results for results is the same as MAX.


    This page titled 19.3: Exercises is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ed Jorgensen.

    • Was this article helpful?