home current projects technical training more about us contact us
top image

Best Practices in Multithreaded Windows Programming

This 2 or 3-day lecture-lab course (the length is customized to client requirements) reviews core topics and emphasizes advanced topics, including performance, scalability, and parallelism on multiprocessor systems.

Extensive hands-on exercises (the exercises are optional; some clients prefer demonstrations), using Microsoft Visual Studio, allow participants to develop, enhance, and debug practical and realistic multithreaded applications that illustrate the topics discussed in the lectures. Complete solutions are provided in all cases, and many of the solutions can be used as the foundation for future application development. All programs run on both 32-bit and 64-bit systems, and Windows 7 features are exploited as appropriate.

The course and the lab exercises concentrate on the core issues and do not use GUI interfaces, although graphical user interfaces can be added to the code. Many of the topics are appropriate when building servers.

Audience: Software engineers and programmers, including those with some experience with threads who need to learn how to develop reliable, high-performance multithreaded Windows client, desktop, and server applications.

Prerequisites: Knowledge of C (or C++, C#, Java, etc.) programming, experience developing Windows applications with Microsoft Visual Studio (helpful, but not required). Prior experience with Windows thread management and synchronization is helpful, but not required.

COURSE SCHEDULE

There are 3-4 sessions per day, depending on the pace; each session consists of a lecture with demonstrations followed by a lab. Average session time is 90 minutes. A one-hour lunch break is recommended. Each day normally runs 7.5 hours (including lunch); for example, 9:00 – 4:30. The instructor will be available for as long as required after each session.

Session 1. Windows Thread Management

  1. Process and Thread Overview
  2. Thread Management
  3. Waiting for Thread Termination
  4. The C Library and Threads
  5. Demonstration: Building a Threaded Application
  6. Thread Priority, Scheduling, multiprocessor Impact
  7. Debugging Techniques - Introduction (There is additional coverage during the exercises
 Session 2. Windows Synchronization
  1. Need for Synchronization
  2. Thread Synchronization Objects
  3. CRITICAL_SECTIONs
  4. Deadlocks, Race Conditions, and Other Defects
  5. Interlocked Functions
  6. Mutexes
  7. Events
  8. Semaphores
  9. Slim Reader/Writer (SRW) Locks
  10. Condition Variables
 Session 3. Performance Impact and Guidelines
  1. CRITICAL_SECTION – Mutex Tradeoffs
  2. Multiprocessor Impact
  3. Locks and Performance Impact. Minimizing Lock Usage
  4. Slim Reader/Writer (SRW) Locks and Condition Variales
  5. Processor Affinity
  6. Tuning with CS Spin Counts
  7. Performance Guidelines and Pitfalls
 Session 4. Thread Safety, DLLs, and Thread-Local Storage
  1. Multithreading Persistent State Problem
  2. The DllMain function
  3. Thread Local Storage
  4. TLS-DLL Demonstration: Message-Based Socket communication
  5. Thread-Safe Libraries w/o TLS: State Parameters
 Session 5. Threading Models for Reliability and Performance
  1. Multithreading Models
  2. Data Parallelism and File/Stream Processing
  3. Computational Parallelism
  4. Condition Variable Usage
  5. Thread Pools
  6. More Performance Tradeoffs
  7. Avoiding Incorrect Code - Hints and Guidelines
Session 6. Compound Object Examples and Exercises
  1. Threshold Barrier Problem
  2. A Queue Object and Pipelines
  3. Demo: Multiple Wait Semaphore with Process-Shared Objects
  4. Demo: Batons to Serialize Thread Execution
Session 7. Advanced Windows Threading Features (Optional)
  1. Asynchronous Procedure Calls
  2. Alertable Wait Functions
  3. APCs and the Baton Example
  4. Waitable Timers
  5. Asynchronous I/O Quick Overview
  6. Extended (Callback) I/O NT6 (Vista, Windows 7, ...) Performance
Session 8. Introduction to Pthreads for Application Portability (Optional)
  1. The Pthreads Model and Standard
  2. The Open Source Windows Pthreads Library and UNIX/Linux Portability
  3. Pthreads Thread Management and Synchronization Introduction
  4. Performance Comparisons
  5. Pros and Cons
footer