CSE 532S Atomic Types 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 e-mail your answers to the cse532@seas.wustl.edu course e-mail account with Atomic Types Studio in the subject line.

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. Open up Visual Studio 2013, make sure your settings are for C++, and create a new project for this studio (for example named something like atomic_types).

    In the main C++ source code file for the project (which should be named something like atomic_types.cpp) please modify the main function signature so that it looks like the standard (i.e., portable between Windows and Linux) main function entry point for C++: int main (int, char * [])

    In your main function, declare instances of the various atomic_types listed in tables 5.1 and 5.2 of the required course text book ("C++ Concurrency in Action" by Williams, referred to as [Williams] on the course web site, and in the rest of this studio description), and see which of them are supported by Visual Studio 2013 (don't forget to include the <atomic> library, etc.).

    Build and run your program and as the answer to this exercise, please list all of the atomic types that are supported in Visual Studio 2013 on the windows lab machines (a.k.a. the studio environment).

  3. For each atomic type that is supported (per the previous exercise) and that is not always guaranteed to be lock free, test whether or not it is lock free using the is_lock_free() method.

    Build and run your program, and as the answer to this exercise, please list all of the atomic types that are lock free in the studio environment, and then list all of the atomic types that are not lock free in the studio environment.

  4. Implement listing 5.5 from [Williams], but instead of having an assert for variable z (and you can leave off including the <assert.h> library) please have your program print out the value of variable z at the end of your program.

    Also modify your program so that the main function accepts a single command line argument for the number of times to run the test (which defaults to 1 if no command line argument is given) and then loops that many times: resetting the values of the x and y (but not z) variables, and then launching the two threads and then joining with both of them, each time through the loop.

    Build and run your program with different numbers of iterations of the test, and as the answer to this exercise please indicate for each run: (1) how many iterations were run, and (2) what value of z was printed out.

  5. Repeat the previous exercise, but modify your code so that instead of using relaxed memory consistency (memory_order_relaxed) it enforces a sequential consistent ordering (memory_order_seq_cst).

    Build and run your program with the same set of trials as in the previous exercise, and as the answer to this exercise please indicate: (1) whether (and if so how) the behavior changed, and (2) why you think it did or did not change based on the program outputs for each exercise.

  6. Repeat the previous exercise, but modify your code so that it enforces acquire-release ordering instead of enforcing a sequential consistent ordering.

    Build and run your program with the same set of trials as in the previous two exercises, and as the answer to this exercise please indicate: (1) which one (or perhaps both) of the previous exercises showed program behavior that was most similar to that seen in this exercise, and (2) why you think that.

    Enrichment Exercises (Optional)

  7. Modify your code from the previous exercises so that it again uses relaxed memory consistency (memory_order_relaxed), but then add a memory fence (or fences) to re-establish strict synchronization.

    Build and run your program with the same set of trials as in the previous three exercises, and as the answer to this exercise please (1) show your code and then indicate: (2) which one (or two or three) of the previous exercises showed program behavior that was most similar to that seen in this exercise, and (3) why you think that.

  8. Explore transitive synchronization, release sequences, or other features of the C++11 memory model and atomic types, as in [Williams]. As the answer to this exercise, please describe what you implemented, how you evaluated it, and what you observed.

  9. Try out any of the previous exercises on another machine, in another compiler, etc. (e.g., in g++ on shell.cec.wustl.edu). As the answer to this exercise, please describe the platform and compiler you used, whether you noticed any differences in program behavior on it vs. on the windows lab machines, and why you think there were (or were not) any differences.