Operating Systems :: Project Pages :: Project 4

Project 4: Threads in C++11

Revision dated 3/21/16

Educational Objectives: After the assignment the student should be able to:

  • Demonstrate a working knowledge of C++11 thread library and use it to cure/prevent race conditions.
  • Demonstrate a working knowledge of C++11 thread support system and use it to cure/prevent deadlocks.
  • Explain the concept of RAII as it applies to thread management.
  • Effectively use RAII in thread management.
  • Effectively avoid busy-wait loops in threads.
  • Effectively control resources accessed by miltiple threads.
  • =======================================================================
    Rubric used in assessment
    -----------------------------------------------------------------------
    builds:
     race.x                                                 [0 .. +5]    5
     pro-con.x                                              [0 .. +5]    5
    tests:
     race.x                                                [0 .. +30]   30
     pro-con.x                                             [0 .. +30]   30
    code evaluation:
     correct and appropriate use of RAII                 [-30 .. +10]   10
     correct and appropriate use C++11 thread support    [-30 .. +10]   10
     general practice (*)                                [-30 .. +10]   10
    -----------------------------------------------------------------------
    late fees                            [4 pts per dated submission]  ( 0)
                                                                        --
    total:                                                   [0..100]: 100
    =======================================================================
    

    (*) See code standards.

Operational Objectives:

  • Use C++11 thread management tools to correct the program race0.cpp so that no data race conditions can occur.
  • Use C++11 thread management tools to correct the program pro-con0.cpp so that no deadlocks can occur.

Deliverables: Two files: race.cpp and pro-con.cpp.

C++11 Thread Support

Please see the on-going writeup here: C++ Thread Library. The short Bo Qian videos 1-6 will be helpful as well.

Procedural Requirements

  1. Copy all of the files in LIB/proj4 into your proj4 directory. Note that deliverables.sh and a makefile are supplied.

  2. Copy race0.cpp to race.cpp and modify the code in race.cpp to prevent data race conditions.

  3. Copy pro-con0.cpp to pro-con.cpp and modify the code in pro-con.cpp to prevent deadlocks.

  4. Submit the assignment using the command submit.sh.

    Warning: Submit scripts do not work on the program and linprog servers. Use shell.cs.fsu.edu to submit assignments. If you do not receive the second confirmation with the contents of your assignment, there has been a malfunction.

Technical Requirements and Specifications

  1. Use RAII to handle possible unusual exits from scope, such as exception throws.

  2. Have no "busy-waiting" loops.

  3. Do not modify "0" versions below the indicated location in the file.

  4. Do not call thread "detach".

  5. Programs must build without errors or warnings using the supplied makefile:

    make race.x     # builds race.c
    make pro-con.x  # builds pro-con.x
    
  6. The possibility of race conditions must be eliminated.

  7. Access to shared resources must be effectively controlled.

Hints:

  • Please read and understand the supplied source code in: race0.cpp, pro-con0.cpp, and random_demo.cpp before beginning your own code modifications.

  • The supplied buffer.h provides an implementation of the Queue API that has its own self-contained diagnostics and allows setting of a bound for buffer size. Note that this is not a deliverable. You can assume that a copy of the file will be in your portfolio.

  • The makefile builds both project executables and a demo program on random distributions:

    make random_demo.x # builds random_demo.x
    make race.x        # builds race.x
    make pro-con.x     # builds pro-con.x
    make               # builds all 3