Courses/Computer Science/CPSC 457.W2012/Lecture Notes/Threads

Jump to: navigation, search


In this session, we will cover two topics. The first will be to get our hands dirty and modify (in a very simple way) and compile the kernel.

We will also revisit our discussion of concurrency at the level of a threading library. We will remind ourselves about how threads are represented in the (Linux) kernel and touch on some alternative approaches to thread support.

We will dwell on threads only briefly, because we delegate learning about some of the practical aspects of the pthreads library API to a couple of tutorial sessions. Between the chapter in MOS, the tutorials, the few minutes on the case study today, and homework 3, you should come away with a good foundation for future thread-based programming.


Misc. Topics

  • HW2 questions and clarifications
  • Midterm questions and clarifications
  • HW3 released.
  • Finish off previous discussion and takeaway lessons.
  • vmrun utility (if time)

A Glance At Modifying and Compiling the Kernel

  • Goal: understand what it takes to make a very basic kernel modification
    • task: add a field to task_struct, expose it via /proc/PID/status
    • 457field / TRUSTED / UNTRUSTED
  • The process
    • download source
    • read build documents
    • Makefile mods
    • config options
    • select something to change
    • set/extract this state
    • compile
    • patch/diff
  • compiling the kernel


  • Recall: clone and vfork (look at flags and arguments)
  • Define / explore semantics of relationship between threads, lightweight processes, and processes
  • Thread properties: identity, stack, attributes, threadgroup
    • example: java threads
    • example: pthreads
  • pthreads API overview (more in the tutorial)

We will examine the use of pthreads through a simple case study. See Libpcap_tutorial


This DailyDave discussion thread is interesting reading that points out that traditional thread-based programming is an obsolete model, particularly for asynchronous, high-performance, highly concurrent, parallel programming tasks and environments.


The readings for tonight preview the next topic: Deadlocks.

  • MOS: 6.2 "Introduction to Deadlocks" (NB: MOS 6.2.1 should be memorized!)
  • MOS: 6.4 "Deadlock Detection and Recovery"
  • MOS: 6.5 "Deadlock Avoidance"
  • MOS: 6.6 "Deadlock Prevention"