This lecture is an introduction to both Windows and C++11 Threads. Windows threads are managed by the operating system
and accessed throuht system calls. C++11 threads are class wrappers around OS threads and are portable across popular platforms,
i.e., Windows, Linux, and OSX.
Readings and Activities for the Week:
-
CPPPL: Chapters 41 and 42
CPPSL: Chapter 18 - Look over code:
Glossary of Terms
-
Thread:
A block of processing instructions, defined by a function passed to the operating system (OS), that executes in a processor core, and is started and stopped by the OS. A thread often runs in an environment containing many other threads that are sequenced in short time-slices by the OS to behave like concurrent processing. A thread may run continuously in a core if there are no other threads contending for that resource. -
Lock:
An OS construct that provides ownership to a single thread, making any other thread, that attempts to acquire the lock, wait for the owning thread to release it. Locks are used to provide exclusive access to some resource for reading and writing. A lock has a signaled state that is used to provide blocking of non-owning threads. -
Race Condition:
A body of code has a race condition when the state of its resources depends on the timing of two or more threads. For example, a read/write conflict occurs when one thread begins to modify a resource, a string perhaps, completes its time slice before completing the modification, and another thread reads the, probably invalid, resource. -
Synchronization:
The use of locks to avoid race conditions.
-
Projects:
-
Sample Project #1,
Code folder
Lexical scanner -
Sample Project #2.
Code folder
Rule-based parser -
Sample Project #3,
Code folder
Parser with Abstract Syntax Tree -
Sample Project #4,
Code folder
Code Analyzer
-
Sample Project #1,
Code folder
-
Threads and Synchronization
Windows and C++11 Threads:
- Motivation:
- The way Windows (and other OSes) work:
- Win32 and C++11 Threads Presentation, pptx
- Win32 Thread Details, doc
- Win Platform threads
-
Simple callable objects demo
Callable objects are very useful for defining thread processing. -
Lambda Capture
Demos for various options when capturing data with lambdas. -
C++11 Concurrency
A series of basic demos that cover most of what you need to know for the midterm and projects. -
Blocking Queue
Thread safe queue that blocks on dequeuing an empty queue. -
Tasks and Threadpool
Provides a ThreadPool class. Task is a wrapper around a static ThreadPool. -
C++11 Thread Techniques
Illustrations of how to do interesting things that are often needed in project designs. -
Queued Messages
Passes messages between threads using Blocking Queue. -
Asynchronous Systems,
pptx
Presentation on the fundamentals of concurrent systems
The resources, listed below, are less important and you can safely skip for now.-
Custom Threads and Locks Classes
C++ class encapsulating Win32 threads. This was written before C++11 and is included only to show how creating a thread class can be accomplished. - Create Child Process - MSDN
-
References:
-
EXtensible Markup Language
XML Presentation, ppt
You may need to use XML in the bodies of some of your messages to convey structured information. -
Preparation for Synchronous Discussion:
- Go to cppreference.com and lookup Condition_Variable. Be prepared to discuss how that was used in the C++11 Blocking Queue.
-
Lecture Take-aways:
The most important things we discussed today were: