CSC 362 Multithreading C++ 2015
CSC 362 Multithreading C++ 2015
CSC 362
instructor: Ed Keenan
email: [email protected]
office hours: Mon (4-5pm in office & 9-10pm in classroom) or by email appointment
office: CDM 830
phone: (312)362-6747
website: piazza.com/depaul/spring2015/csc462 (Preferred communication)
lecture: CDM 222, Monday 5:45-9:00pm
Desired to Learn (D2L): d2l.depaul.edu (Grades, Viewing lectures, Announcements)
Version Control: perforce: 140.192.39.61:1666
Description
Applied C++ concurrency and multithreading fundamentals. Basics threading concepts: process model,
threads, stacks, fibers, mutexes, semaphores, atomics and events. Understanding synchronous /
asynchronous interactions and behavior of threads. Using managed thread pools and queues in
applications. Understanding advanced C++ language features relating to the memory model and the
threading support.
Prerequisites
Reference Material
Learning Objectives
• Students will be able to demonstrate basic thread knowledge (threads, mutexes, semaphores,
atomics, events)
• Students will be able to create design multithread applications using Lock-Based concurrent
data structures.
CSC 362: C++ Multithreading
contention)
• Students will refactor single threaded applications into a multi-threaded solutions
1
Grading
• 20 % - Simplified Threading program
o Program using basic multithreading primitives
Several fixed threads, Mutexes, Callbacks, Critical Sections
• 10% - Book Demos
o Sample code from book: Submitted to Perforce with commentary
• 30 % - Conversion problem
o Puzzle program or something similar
Converting a single thread system into multiple threaded solution
• 30% - Managing multiple thread in pools
o Creating a threading pool system.
Manage and control thread execution and priorities.
o Spawning multithreaded program
Creating a dynamically spawning application of autonomous agents
Design and implemented using the thread pool system
• 10 % - Final Exam
Software
• Microsoft Visual Studio 2012 (ultimate edition - Recommended)
o DePaul MSDNAA link Microsoft_Visual_Studio_Ultimate_2012
o C# and C++ install (future classes)
o Microsoft Visual Studio 2013 is not used in this class.
• Perforce - Visual Client (p4v)
o www.perforce.com
• Download and configuration instructions will be provided in class
o Server address: 140.192.39.61:1666
Topics:
• Debugging
Syllabus - 29 March 2015
• Testing
• C++ 11 Language Features
Primitives
• Threads
• Fibers
2
• Atomics
• Mutexes
• Semaphores
• Events
Phase 1 : Basics
• Programming Assignment
o (20%) PA1: Simplified Threading program
Program using basic multithreading primitives
• Several fixed threads, Mutexes, Callbacks, Critical Sections
o Book Demos
Sample code from book: Submitted to Perforce with commentary
• Week 1
o Introduction to Concurrency
o Launching a thread
o Waiting for a thread to complete
o Passing arguments to a thread
o Transferring ownership of a thread
• Week 2
o Sharing Data between thread
o Race conditions
o Protecting shared data with mutexes
o Deadlocks
o Flexible locking (C++ specifics)
o Transferring mutex ownership
o Recursive locking
• Week 3
o Synchronization concurrent operations
o Building a thread-safe queue
o Waiting for an event or other condition
o Waiting for one-off events with futures
o Return from background tasks, promise - future
o Waiting with a time limit
o Clocks, Timepoints
• Week 4
o C++ memory model
o Atomic Types in C++
o Synchronizing operations and enforcing ordering using Atomics
o Fences
CSC 362: C++ Multithreading
Syllabus - 29 March 2015
3
Phase 2: Refactoring existing solutions
• Programming Assignment
o (30%) PA2: Conversion problem
Converting a single thread system into multiple threaded solution
• Example problems:
o NxN sliding puzzle
o Maze program
o Book Demos
Sample code from book: Submitted to Perforce with commentary
• Week 5
o Lock-based concurrent data structures
o A thread-safe stack using locks
o A thread-safe queue using locks and condition variables
o A thread-safe queue using fine-grained locks and condition variable
o Writing a thread-safe list using locks
• Week 6
o Designing lock-free concurrent data structures
o Non blocking data structures
o Lock-free data structures
o Writing a thread-safe stack without locks
o ABA problem
• Week 7
o Designing concurrent code
o dividing work between threads
o Dividing work by task
o performance of concurrent code
o Oversubscription and excessive task switching
o Hiding latency with multiple threads
o Improving responsiveness with concurrency
4
Phase 3: Threading system / management
• Programming Assignment
o (30%) PA3: Managing multiple thread in pools
Creating a threading pool system.
• Manage and control thread execution and priorities.
Spawning multithreaded program
• Creating a dynamically spawning application of autonomous agents
• Design and implemented using the thread pool system
Examples:
• Interactive spawning / dispatch / threading system
o Genetic bug spawn / growth / death - Gui application
o or Desktop Tower Defense
o Book Demos
Sample code from book: Submitted to Perforce with commentary
• Week 8
o Advanced thread management
o Thread pools
o Interrupting threads
o Launching and interrupting another thread
o Detecting that a thread has been interrupted
o Interrupting other blocking calls
• Week 9
o Debugging multithreaded applications
o Types of concurrency-related bugs
o Race conditions
o Unwanted blocking
o Locating concurrency-related bugs by testing
• Week 10
o Performance tuning
o Contest
5
Perforce Submissions
• Everyone is expected to submit at least 10 submissions a week to perforce.
• The biggest reason students get into trouble with software design:
o Not working on the material frequently enough
o Taking too large of a bite of the design
• Both are fixed with this Perforce RULE
• Even my simplest programs take 10-20 submissions.
o For these project assignments my average is 40-400 submissions, so 10 will be no problem.
• Detailed perforce changelist comments are expected
NOTE: Do NOT post until you have watched the entire lecture FIRST (in class or online)
This will prevent frustration on all sides (members asking or answering questions)
CSC 362: C++ Multithreading
Syllabus - 29 March 2015
6
Collaborating together on programming assignments
7
Schedule:
Week Lecture Work
Overview Chapter 1-2
1 C++ 11 Review PA1 - assignment
Thread Creation
Sharing Data Chapter 3
2 Deadlocks
Mutex
Synchronization Chapter 4
3 Waiting for Events
Clocks
C++ Memory Model Chapter 5
4 Atomic Types
Fences
Lock-Base concurrent structures Chapter6
5 Thread-safe Queues PA2 - assignment
PA1 - due before class
Lock-Free concurrent structures Chapter 7
6 Non-Blocking
ABA problem
Dividing work between threads Chapter 8
7 Oversubscription excessive switching
Improving responsiveness
Thread Pools Chapter 9
8 Interrupting Threads PA3 - assignment
Blocking calls
PA2 - due before class
Debugging multithreading Chapter 10
9 Race conditions
Unwanted blocking
Performance tuning
10 Contest
Final Exam
11 PA3 - due before exam
8
Course Policies
Changes to Syllabus
This syllabus is subject to change as necessary during the quarter. If a change occurs, it will be thoroughly
addressed during class, posted under Announcements in D2L and sent via email.
Evaluations are a way for students to provide valuable feedback regarding their instructor and the course. Detailed
feedback will enable the instructor to continuously tailor teaching methods and course content to meet the
learning goals of the course and the academic needs of the students. They are a requirement of the course and are
key to continue to provide you with the highest quality of teaching. The evaluations are anonymous; the instructor
and administration do not track who entered what responses. A program is used to check if the student completed
the evaluations, but the evaluation is completely separate from the student’s identity. Since 100% participation is
our goal, students are sent periodic reminders over three weeks. Students do not receive reminders once they
complete the evaluation. Students complete the evaluation online in CampusConnect.
This course will be subject to the university's academic integrity policy. More information can be found
at http://academicintegrity.depaul.edu/. If you have any questions be sure to consult with your professor.
Academic Policies
All students are required to manage their class schedules each term in accordance with the deadlines for enrolling
and withdrawing as indicated in the University Academic Calendar. Information on enrollment, withdrawal,
grading and incompletes can be found at: cdm.depaul.edu/enrollment.
Students who feel they may need an accommodation based on the impact of a disability should contact the
instructor privately to discuss their specific needs. All discussions will remain confidential.
To ensure that you receive the most appropriate accommodation based on your needs, contact the instructor as
early as possible in the quarter (preferably within the first week of class), and make sure that you have contacted
the Center for Students with Disabilities (CSD) at: [email protected].
Retroactive withdrawal
CSC 362: C++ Multithreading
Syllabus - 29 March 2015
This policy exists to assist students for whom extenuating circumstances prevented them from meeting the
withdrawal deadline. During their college career students may be allowed one medical/personal administrative
withdrawal and one college office administrative withdrawal, each for one or more courses in a single term.
Repeated requests will not be considered. Submitting an appeal for retroactive withdrawal does not guarantee
approval. Information on enrollment, withdrawal, grading and incompletes can be found at:
http://www.cdm.depaul.edu/Enrollment-Policies.aspx