
Advance to master multithreaded design patterns in C/C++ using posix threads. Explore thread management, pools, barriers, monitors, and producer–consumer synchronization with practical, advanced examples.
Define a thread data structure and prototype three APIs for a multithreaded library, then implement create, run, and a general or dance mode toggle to initialize and start threads.
Learn how to pause and resume pthreads using mutex and condition variables, including cancellation points and building custom apis, while avoiding invariance and resource leaks.
Enhance the thread data structure with a TradeSports function pointer, its argument, a 32-bit flags field, a mutex, and a condition variable to enable pause and resume in pthreads.
Implement four thread APIs for setting the pause function, pausing, resuming, and testing unpause—using mutex locks, state flags, and a condition variable to control pausing and resuming threads.
Take a learning break to explore the globalist linked list as a new approach, using it as a supporting data structure for future assignments with a working implementation.
Explore how thread pools park ready threads on a condition variable, assign work without creating new threads, and wake workers via signaling for efficient task execution.
Learn how a thread pool boosts performance by reusing threads for packet processing, reducing expensive system calls, limiting thread counts, and reusing connections in network applications.
Design a thread pool where the application initializes threads, fetches work from the pool (a function plus argument), executes the work, and recycles threads with optional completion feedback.
Explore thread pool data structures and apis for implementing multithreading design patterns. Build a linked list based thread pool with mutex protection and management apis for adding or removing threads.
Begin implementing a pthreads thread pool by initializing the pool, inserting and fetching threads with a mutex-protected linked list, and starting the dispatch logic while integrating the dual thread library.
Learn to implement a pthreads thread pool API: enqueue threads into the pool, block them on a condition variable, then dispatch by creating the execution unit or signaling the thread.
Learn to implement a thread pool, using a thread execution data object that stores function and data for stage two, and guide threads through stage three with helper APIs.
Demonstrates a thread pool by creating and initializing two threads, dispatching functions that print even and odd numbers in reverse and normal order, with sleeps.
Implement step seven as an optional notification from the worker thread to the application. A boolean flag decides whether the application blocks; use zero semaphores, with condition variables as an alternative.
Implement caller thread blocking with a semaphore in step seven, letting the application block via a block color flag and resume when the worker thread signals, enforcing sequential thread-pool execution.
introduce thread barrier, a barrier synchronization data structure that blocks threads until a specified number arrive, enabling completion of parallel tasks before proceeding.
Understand barrier synchronization in multithreaded programs: a barrier threshold blocks threads at a barrier point until the required number arrives, then releases all and transitions through disposition until completion.
learn to implement the barrier wait api for threads using mutexes and condition variables, handling last-thread signaling, blocking, and disposition states.
Explore how a thread barrier coordinates three threads, synchronizing at multiple barrier points and verifying barrier state before program termination.
Introduce wait queues as a thread synchronization data structure that blocks threads until a routing table entry is ready, simplifying multithreaded design compared to mutexes and condition variables.
Demonstrate the WQ test and wait API implementation, showing how a condition function and a disk mutex block threads until the disk is ready and wake threads on signal.
Compare the test_and_wait API with the standard two-state locking procedure, mapping lock mutex, predicate check, block on the condition variable, wake, recheck, enter the critical section, and unlock.
Implement and initialize wait queues in a pthreads-based multithreading design patterns course, wiring up data structures, APIs, and three-step signaling with mutexes and condition variables.
Design a traffic light data structure with color and direction enumerations, implement a traffic light phase, manage per-face mutex and wait queues, and expose initialization and status APIs.
Model moving traffic with threads approaching traffic light faces, using per-phase wait queues and mutexes, plus thread private data and state enumeration to block on red and resume on green.
Explain what recursive mutexes are, why they prevent deadlocks by allowing the same thread to lock multiple times, and how to enable and use them with POSIX mutex attributes.
Explore when to use recursive mutexes in multithreaded software, showing how nested API locks can deadlock with normal mutexes and how recursive locks enable safe re-entry.
Develop and test a custom recursive mutex by implementing five APIs that mirror the POSIX recursive mutex behavior, ensuring mutual exclusion, proper blocking, and safe unlock usage.
Implement the recursive mutex lock api by handling three cases: free, owned by the current thread, and owned by another thread; block with a condition variable and retry until available.
Explore Reed Wright locks and mutex concepts, review in-built API support, examine use cases, then write your own implementation to gain conceptual clarity.
Explore how read/write locks boost concurrency by allowing multiple readers while writers stay exclusive. Learn read and write lock semantics and the lock/unlock API for safe multithreading.
Explore POSIX pthreads read-write locks: initialize, acquire read or write locks, unlock, and destroy, with a demo and an assignment to implement your own read-write locks using normal condition variables.
Explore a six-thread test of a read-write lock, with three readers and three writers, validating exclusive writer access and concurrent readers in a critical section.
Learn to implement a read-write lock from scratch, ensuring reader and writer coordination, support for recursion, correct unlock semantics, and crash-on-invalid unlock, using only condition variables and mutexes.
Learn to implement a read-write lock using a state mutex, a condition variable, and counters to manage access and ownership by readers and writers.
Implement a write lock api for a read lock object, detailing cases when the lock is available, held by the same writer (recursive), or by another thread (blocked).
Explore how monitors generalize read-write locks to coordinate threads, enabling customizable cooperation schemes and problem-specific synchronization for multithreading with pthreads.
Upgrade the rewrite lock to a monitor by applying five customizations, making the read-write lock configurable, and setting up a monitor directory for upcoming changes.
Implement the replacement property in a pthreads monitor by updating the unlock API to signal waiting readers and writers, achieving symmetric read and write locking.
Testing our custom monitor by modifying the test program to set max readers and max writers, then run and verify the critical section constraints with assertions and runtime output.
This is a sequel Course to Master Class-Multithreading & Thread Synchronization - C/C++, and this course should be done only when the prequel course has been completed unless you have reasonable knowledge regarding how Mutexes and Condition Variables work.
In this course, we shall be Implementing Advanced Thread Synchronization Data Structures and Multithreading based software patterns, with some advanced thread synchronization-based problem-solving. This course uses POSIX threads, hence it is Linux only course. We shall be building upon the knowledge we gathered from the prequel course.
*** However note that the course is highly conceptual and concepts learned can be easily applied to any programming knowledge which supports Multithreading. *** So, Java, C#, Python, Go, Kotlin Programmers do not hesitate to enroll in this course, you can write your own codes based on the concept discussed. This Course is unique and only one of its kind.
The level of this course is Intermediate to Advanced.
Table of Contents
====================
1. Thread Management
2. Pausing and Resuming Threads
3. Thread Pools/Work Crew Model
4. Thread Barriers
5. Wait-Queue Model
6. Recursive Mutexes
What are Recursive Mutexes?
When to use over Normal Mutexes?
Implement own Recursive Mutex
7. Read-Write Locks
What are Read-Write locks ?
What is its benefit?
Implement your own Read-Write lock
8. Monitors
Implement Reader-Writer Monitor
Solving Bridge Problem using Monitors
Guidelines for writing Monitors
Case Study : Covid Vaccination Drive Implementation using Monitors
*** Completed Till here as of 2 Mar 2022 **
9. Assembly Line Model
10. Deadlock Detection and Prevention
11. Other Related Courses on Multi-Threading
Designing Timers
Designing Multi-Threaded TCP Servers
Asynchronous Programming
UnScheduled Topics :
=================
11. Bounded Waiting
12. Fifo (Strong) Semaphores
13. Event Pair Synchronization
14. Inter-Process Synchronization using Semaphores
15. Forking a Multi-Threaded Program
Though We use the C language to demonstrate the concepts, concepts hold good for any programming language. This course is equally valuable for C++ programmers. Other language programmers may also find this course useful as we explain Multithreading concepts close to the ground zero levels with No Abstraction.
At each stage of this Course series, you shall be writing a lot of multi-threaded Codes. So be ready to Master the Multi-threading. Along the journey, we shall cover several interview-favorite topics and Questions to prepare you alongside for interviews.