Everyone:

For the past couple of weeks, we have studied how an operating system virtualizes the CPU by providing processes and scheduling policies. By enabling users to execute multiple jobs simultaneously, the OS enables better utilization of the hardware and allows for more sophisticated workflows. Unfortunately, this multiprogramming ability comes with the cost of complexity due to issues related to concurrency.

This week we will examine both event-based programming and pthreads. Afterwards, we will further explore how to tackle the challenges of concurrency with tools such as locks, condition variables, and semaphores.

TL;DR

For this reading assignment, you are to read about two forms of concurrency: event-based programming via select and poll, and threads ala pthreads, submit your responses to the Reading 04 Quiz, and explore system calls with strace.

Reading

The readings for this week are:

  1. Operating Systems: Three Easy Pieces

    1. Dialogue
    2. Concurrency and Threads
    3. Thread API
    4. Event-based Concurrency

Optional Readings

  1. On the duality of operating system structures

  2. Async IO on Linux: select, poll, and epoll

Quiz

Once you have done the readings, answer the following Reading 04 Quiz questions:

Program

For this week, you are to explore system calls by running strace on your program from Reading 03:

$ cd reading03                # Go to reading03 folder

$ strace -c ./program *       # Trace the system calls used by the Reading 03 program

After running strace a few times, you are to modify program.c in reading04 to print the responses to the following questions:

  1. Order the following system calls from fastest to slowest: open, close, read. (Print response with only a single space between each word)

  2. Considering open, close, and read, which system call is called the most?

  3. Considering open, close, and read, which system call failed the most?

  4. Instead of fork, which system call was used to create a new process?

  5. Considering open and clone, which system call was the slowest (ie. most usecs/call)?

  6. Considering close, stat, and wait4, which system call was the slowest (ie. most seconds)?

Note: We will consider openat to be equivalent to open when examining the strace output.

Note: Subsequent runs of your program may access the filesystem cache and thus have different times from your first invocation. Use the times from the initial (that is, non-cached) run.

Submission

To submit you work, follow the same process outlined in Reading 01:

$ git checkout master                 # Make sure we are in master branch

$ git pull --rebase                   # Make sure we are up-to-date with GitHub

$ git checkout -b reading04           # Create reading04 branch and check it out

$ cd reading04                        # Go into reading04 folder
$ $EDITOR answers.json                # Edit your answers.json file

$ ../.scripts/check.py                # Check reading04 quiz
Checking reading04 quiz ...
      Q1 0.20
      Q2 0.20
      Q3 0.30
      Q4 1.10
      Q5 0.10
      Q6 0.20
      Q7 0.40
      Q8 0.50
   Score 3.00 / 3.00
  Status Success

$ git add answers.json                # Add answers.json to staging area
$ git commit -m "Reading 04: Quiz"    # Commit work

$ $EDITOR program.c                   # Edit your program.c file

$ make test-program                   # Check reading04 program
Testing reading04 program...
   Score 3.00 / 3.00
  Status Success

$ git add program.c                   # Add program.c to staging area
$ git add Makefile                    # Add Makefile to staging area
$ git commit -m "Reading 04: Code"    # Commit work

$ git push -u origin reading04        # Push branch to GitHub

Pull Request

Once you have committed your work and pushed it to GitHub, remember to create a pull request and assign it to the appropriate teaching assistant from the Reading 04 TA List.