Institute for Advanced Professional Studies

POSIX Multithreaded Programming: Servers and Applications




POSIX Workshop Overview:

This hands-on course covers UNIX multithreaded programming using the POSIX 1003.1c interface. A particular emphasis of the course is the design of high-performance servers. We address uniprocessors and multiprocessors, as well as Intel's hyper-threaded processors and the new dual-core CPUs from AMD and Intel. We cover the use and new features of POSIX Threads (also known as pthreads) not only in C programs, but also in C++ programs.

The course has two major themes: Writing reliable, maintainable programs and writing high-performing programs. An important sub theme of the course is determining when it is appropriate to use multithreaded programming techniques. Much of the course is spent learning and practicing how to write, test and enhance multithreaded programs, covering common pitfalls, and working with numerous examples.

50% of this course is devoted to guided, hands-on programming exercises, ensuring that participants gain sufficient experience with multithreaded program design, coding, error detection and debugging techniques. Among the areas emphasized in the course are the special concerns for programming multiprocessors, particularly techniques for taking maximum advantage of the available processors. Participants learn how threads packages are implemented so that they can understand the performance implications of the various approaches when writing multithreaded programs.

A major module focuses on the design of scalable servers. Included here are techniques for improving responsiveness to network requests and for reducing overhead in handling such requests.

IAPS can customize UNIX training to achieve specific organizational objectives. We also offer multithreaded programming training for Windows (Win32), Solaris and Linux for groups developing and supporting embedded real-time systems, as well as desktop, client and server applications on uniprocessor and multiprocessor platforms.


POSIX Workshop Objectives:

Upon successful completion of this course, participants will be able to:

  • Define threads and explain how they are different from processes.
  • Describe what sorts of applications should be written as multithreaded applications.
  • Describe what sorts of applications should not be written as multithreaded applications.
  • Design, write, test and debug multithreaded applications for UNIX systems.
  • Describe the difference between parallelism and concurrency and show how to take advantage of each with threads.
  • Explain what Intel's Hyper-Threading Technology is and describe how multithreaded programs can take advantage of it.
  • Describe the architecture and key features of the latest dual-core processors and explain how multithreaded programs should be designed to harness their computing power.
  • Utilize POSIX standards to write portable multithreaded programs.
  • Describe synchronization and how it applies to multithreaded programs.
  • Use mutexes, condition variables, and semaphores on UNIX systems.
  • Describe what a barrier is and demonstrate how to implement it using POSIX threads.
  • Use assertions and simple verification techniques to demonstrate that a multithreaded program is correct.
  • Explain why some libraries cannot be easily used with multithreaded programs (i.e., are not "thread-safe") and describe the subtle and not-so-subtle errors that could occur when using them.
  • Demonstrate the use of thread specific data and other techniques for dealing with these problems.
  • Use threads to build high-performance server applications.
  • Describe how asynchrony enters into multithreaded programs.
  • Use signals and cancels within multithreaded programs on UNIX systems.
  • Describe the trade-offs between using threads and processes.
  • Coordinate the threads of different processes.
  • Describe how the architecture of multiprocessor computers affects the design of multithreaded programs.
  • Describe the strategies employed in a number of threads implementations and how they affect performance and scheduling.

Topic Outline:

  • Introduction
    • What is concurrency?
    • What is parallelism?
    • What is hyper-threading and on which processors is it available?
    • Why should one write multithreaded programs?
    • Why aren't processes good enough?
    • POSIX 1003.1c: The UNIX threads API
    • Win32 threads: another implementation approach
  • Adding Threads to C Programs
    • Creating and terminating threads
    • Passing arguments to threads
    • C examples
    • Special concerns for object-oriented programs
    • C++ examples
    • Hands-on exercises
  • Synchronization
    • Mutual exclusion with mutexes
    • Condition Variables
    • Semaphores
    • Barriers
    • How best to use the available constructs
    • C and C++ examples
      • Using assertions and simple verification techniques
    • Hands-on exercises
  • Deviations
    • Cancels and cancellation
    • Exception handling
    • UNIX Signals
    • Asynchronous signal safety
    • Hands-on exercises
  • Thread-Safe Libraries
    • Thread safety issues
    • Thread-specific data: Global, but private, data
    • Handling shared storage
    • Examination of example libraries
    • Hands-on exercises
  • Threads and Processes
    • Coordinating the threads of different processes: cross-process synchronization
    • Hands-on exercises
  • Threads and Multiprocessors
    • Problems with the memory model
    • Utilizing multiprocessors effectively
    • Utilizing dual-core and hyper-threaded processors effectively
    • Testing, debugging, and enhancing the reliability and performance of multithreaded programs
    • Hands-on exercises (if a multiprocessor or hyper-threaded processor is available)
  • Designing High-performing Servers
    • Asynchronous vs. Synchronous I/O
    • Designing high-performance servers
    • Designing scalable servers
    • Hands-on exercises
  • POSIX Threads Implementation and Scheduling Issues
    • The implementation of thread support
      • One-to-one model
      • Variable-weight processes
      • Many-to-one model
      • Many-to-many model
      • Scheduler activations
    • Interaction with OS scheduling

Course Duration:

3 days


Intended Audience:

Experienced C and C++ programmers who wish to become competent at writing multithreaded programs, such as high-performing high-reliability servers, on UNIX platforms


Technical Prerequisites:

Participants should be experienced C and C++ programmers: They must be comfortable with all the major features of the languages, including pointers, dynamic storage allocation, classes, abstract types, and inheritance. They should have experience programming on UNIX systems and should know how to use standard facilities to edit, compile, and debug applications.


Course Format:

Hands-on lecture/workshop




© Copyright 1997-2015 Institute for Advanced Professional Studies (IAPS)