We may earn an affiliate commission when you visit our partners.
Abhishek CSEPracticals, Shiwani Nigam, and Ekta Ekta

Welcome to the Course Series on Multi-Threading - The Master Class Course on Threads.

This course is for those who want to develop fundamental concepts on Multi-threading and related concepts. In this course, we shall be going to cover Multi-threading concepts based on Pthreads (POSIX threads) on the Linux platform.

Read more

Welcome to the Course Series on Multi-Threading - The Master Class Course on Threads.

This course is for those who want to develop fundamental concepts on Multi-threading and related concepts. In this course, we shall be going to cover Multi-threading concepts based on Pthreads (POSIX threads) on the Linux platform.

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 No Abstraction.

We shall discuss several concepts involved in multithreading and demonstrate each concept through a sample program. Several Important Concepts include but are not limited to - Deadlocks, Mutual Exclusion, Atomicity, Thread Synchronization, Race Conditions, Thread forking, and many more.

In the Next Installment of this course, we shall extend our knowledge of Multi-threading to Advance Concepts, including mini-projects on Multithreading and Thread Synchronization.

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.

Best of luck.

Table Of Contents:

= = = = = =

1. Understanding Threads

  • Thread Creation & Termination

  • Race condition on Thread Creation

  • Passing Argument to Thread Function

  • Stack Memory Mgmt for Multi-threaded Programs

  • Thread Scheduling

2. Understanding Concurrency and Parallelism

  • Singlularism Vs Concurrency Vs Parallelism

  • Concurrent Process Design - 2 Examples

  • Threads as Light Weighted Process

  • Overlapping and Non-Overlapping Work

3. Joinable and Detached Threads

  • Joinable Vs Detached Threads

  • How to Join a thread

  • Whom to Join?

  • Sample - Map-Reduce Program

4. Inter Thread Communication

  • Understanding Callbacks and Function Pointers

  • Best way to implement ITC

  • Implementing Notification Chains

    • A Publisher Subscriber Model

    • How to Subscribe/UnSubscribe

    • How to send Notification to Subscribers               

5. Asynchronous Thread Cancellation

  • Thread Cancellation

  • Asynchronous and Deferred Thread Cancellation

  • Problem with Async Thread Cancellation

    • Resource Leaking

    • Invariants

    • Deadlocks

  • Concept of Thread Cleanup Handlers

    • Prevent Resource Leaking                                        

    • Data Structure Corruption - Invariants

    • Cancellation causing Deadlocks

6. Deferred Cancellation

  • Understanding Deferred Cancellation

  • Implementation

7. Listener Threads - Responsibility Delegation

  • Why Listener threads?

  • Designing Listener threads

  • Code Changes and Demo                               

  • Cancellation of blocked Threads

8. Thread Synchronization

  • Critical Section

  • Mutex Rules

  • Mutex Locking

    • Mutex Locking - Code Locking

    • Mutex Locking - Data Locking

  • Mutex based APIs

  • Mutexes in Action

9. Deadlocks

  • What are deadlocks and why do they happen?

  • Necessary conditions for Deadlock to happen

  • Mutex lock Ordering Causing Deadlocks                            

10. Condition Variables

  • Understanding CV

  • CV Vs Mutex

  • Wait( )  &  Signal( )

  • Producer-Consumer Thread Synchronization

  • Spurious Wake Ups

  • Thread Vs Resource Specific CV

  • Broadcasting a CV

  • Implement Producer-Consumer Problem           

11. Dining Philosopher Problem

  • Problem Description

  • Data Structures Setup                           

  • Assignment Program Setup

  • Flowchart/Algorithm Discussion

  • Final Implementation (Step by Step )

12. Semaphores

  • Introduction

  • Semaphores Vs Mutexes 

  • How Semaphore work 

  • Strict Alternation Problem

  • Semaphore Implementation

  • Semaphore Types

  • Strong and Weak Semaphores

Listing Upcoming Advanced Multi-Threading Topics for Sequel Course ( Under Progress )

= = = = = = = = = =  = = = = = =  = = = = = =

1. Pausing and Resuming Threads

2. Thread Pools

3. Standard Problems - Reader/Writer Problem

4. Implementing Thread Barriers

5. Implementing Thread Monitors

6. Solving Sync Problems using Monitors

7. Deadlock Detection and Prevention

8. Wait  Queues

9. Implement Timers using Threads

10. How to fork a multi-threaded process

11. Process Synchronization using Named Semaphores

Happy Learning.

Featured Review

This course is amazing. I'm so glad the instructor decided to offer courses on Udemy. First, it's very rare to find courses on more advanced subject matter. As a software developer, I love learning but am often disappointed that Udemy largely has beginner-oriented material (understandably so). Then there's the CSEPracticals courses. I learned a LOT here. This is some valuable, real world stuff. It's incredibly useful to learn how multi-threading in C is actually applied in real world use cases and to implement these use cases on your own. The instruction was clear, the information valuable. The code samples are plentiful. The instructor is clearly very knowledgeable about networking and so the course examples tend to lean in that direction. I'm very impressed and had a LOT of fun with this course. I can't wait to check out the other ones by CSEPracticals.

I have just finished this course, and I cannot recommend it more. Its an excellent course on multi-threading and achieves exactly what it intends to from the start. Some features of this course 1) You write a lot of code, and you become more confident in using the pthread library ( along with some other things, I learned how important proper use of assert function can be). 2) Abishekh goes in depth on different synchronization method and shows you have to build them using fundamental tools like mutex and condition variables. This gives you a lot of confidence, and you can build your own in future in case your chosen OS or library does not have those built-in. This in my opinion is the biggest strength of the course. 3) The team of CSE Practicals is very responsive and you can expect to get a response on your queries within a very reasonable time-frame. Ongoing to the course sequel now. Ovais

Enroll now

What's inside

Learning objectives

  • Multithreading fundamentals
  • Concurrency
  • Mutual exclusion vs atomocity
  • Thread synchronization techniques
  • Writing thread safe codes
  • Mutexes, semaphores
  • Signaling and wait
  • Interview questions

Syllabus

Concurrent Process Design - Example 1
Concurrent Process Design - Example 2
Why Threads are called Light Weighted Processes ?
Overlapping and Non-Overlapping Work
Read more

This can be Interview Question.

This can be an Interview Question. Very important.

Interview Questions :

Different between Parallel Processing and Concurrency.

Difference between Multi-Tasking and Parallel Processing.

Compile using below commands :

gcc -g -c rtm_publisher.c -o rtm_publisher.o

gcc -g -c rt.c -o rt.o ( assuming you have renamed rt_raw.c and rt_raw.h to rt.c and rt.h )

gcc -g rtm_publisher.o rt.o  -o main.exe -lpthread

Run :   ./main.exe

Traffic lights

Read about what's good
what should give you pause
and possible dealbreakers
Uses the C language to demonstrate multithreading concepts, which are applicable to other programming languages like C++ and can be adapted by programmers in other languages
Covers interview-favorite topics and questions, which can help learners prepare for job interviews related to multithreading and concurrent programming
Explores advanced concepts like thread pools, monitors, deadlock detection, and wait queues, which are essential for building robust concurrent applications
Requires familiarity with the C language and comfort with pointers, as the course uses C to demonstrate multithreading concepts, which may pose a challenge to some learners
Focuses on Pthreads (POSIX threads) on the Linux platform, which may limit its direct applicability to other operating systems without modification
Builds fundamental concepts on multithreading and related concepts, which is valuable for those seeking a deeper understanding of concurrency and parallelism

Save this course

Create your own learning path. Save this course to your list so you can find it easily later.
Save

Reviews summary

Deep dive into pthreads multithreading

According to learners, this course offers a largely positive and in-depth exploration of multithreading and thread synchronization fundamentals using Pthreads. Students found the coverage of concepts like mutexes, condition variables, and deadlocks particularly clear and valuable. The emphasis on hands-on coding with real world use cases and plentiful code samples is a major strength, preparing them well for professional tasks and interviews. The instructor knowledge and responsive team are also highlighted. While the production quality (audio/video) was noted as inconsistent by some, the core technical content received widespread praise. This course is the first part of a series.
This course is the first part of a multi-part series on multithreading.
"Ongoing to the course sequel now."
"I understand this is only Part A. Looking forward to the next part."
"In the Next Installment of this course, we shall be going to cover Multi-threading concepts based on Pthreads (POSIX threads)..."
Instructor is knowledgeable and team provides responsive support.
"The instructor is clearly very knowledgeable..."
"The team of CSE Practicals is very responsive and you can expect to get a response on your queries within a very reasonable time-frame."
"The instructor's responsiveness in the Q&A is also a huge plus."
"The instructor knows his stuff and explains complex topics well."
Provides ample coding exercises and practical examples.
"You write a lot of code, and you become more confident in using the pthread library"
"Incredibly useful to learn how multi-threading in C is actually applied in real world use cases..."
"The code samples are plentiful."
"The examples like the Dining Philosophers problem are great for applying the concepts."
Offers in-depth coverage of key threading principles.
"This course is absolutely fantastic for understanding multithreading from the ground up using Pthreads."
"Goes in depth on different synchronization method... gives you a lot of confidence"
"Learned so much about thread synchronization that I wasn't getting from documentation or other tutorials."
"Very detailed and covers the core Pthreads concepts thoroughly."
Production quality (audio/video) is inconsistent for some.
"My only minor quibble is that the video quality isn't always perfect, and sometimes the audio could be clearer."
"The production quality (audio/video) is not the best. Needs some polish."
"Poor audio and video quality are distracting."
"Needs better editing and presentation."

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Part A - Multithreading & Thread Synchronization - Pthreads with these activities:
Review Operating System Concepts
Refresh your understanding of operating system concepts, particularly those related to processes, threads, and concurrency, to provide a solid foundation for multithreading.
Browse courses on Operating Systems
Show steps
  • Review OS textbooks or online resources.
  • Focus on chapters related to processes, threads, and synchronization.
  • Do practice questions on concurrency and process management.
Read 'Advanced Programming in the UNIX Environment' by W. Richard Stevens and Stephen A. Rago
Study a classic text on UNIX system programming to gain a deeper understanding of the operating system environment in which pthreads operate.
Show steps
  • Obtain a copy of 'Advanced Programming in the UNIX Environment'.
  • Read the chapters related to processes, threads, and interprocess communication.
  • Experiment with the code examples provided in the book.
Read 'Programming with POSIX Threads' by David R. Butenhof
Study a comprehensive guide to POSIX threads to gain a deeper understanding of the underlying concepts and practical implementation details.
Show steps
  • Obtain a copy of 'Programming with POSIX Threads'.
  • Read the chapters relevant to thread creation, synchronization, and management.
  • Experiment with the code examples provided in the book.
Four other activities
Expand to see all activities and additional details
Show all seven activities
Implement Producer-Consumer Problem
Practice implementing the producer-consumer problem using pthreads and synchronization primitives to reinforce your understanding of thread synchronization.
Show steps
  • Write a program with producer and consumer threads.
  • Use mutexes and condition variables for synchronization.
  • Test the program with multiple producers and consumers.
Create a Thread Synchronization Cheat Sheet
Summarize key concepts and code snippets related to thread synchronization techniques to create a handy reference guide.
Show steps
  • Review the course materials on mutexes, condition variables, and semaphores.
  • Create a document summarizing the key concepts and code examples.
  • Organize the information in a clear and concise manner.
Build a Multithreaded Web Server
Apply your knowledge of multithreading to build a practical application that handles concurrent client requests.
Show steps
  • Design the architecture of the web server.
  • Implement thread creation and management for handling requests.
  • Use mutexes and condition variables to protect shared resources.
  • Test the server with multiple concurrent clients.
Contribute to a Pthreads Project
Contribute to an open-source project that uses pthreads to gain practical experience and learn from experienced developers.
Show steps
  • Find an open-source project that uses pthreads.
  • Identify a bug or feature to work on.
  • Submit a pull request with your changes.

Career center

Learners who complete Part A - Multithreading & Thread Synchronization - Pthreads will develop knowledge and skills that may be useful to these careers:
Concurrency Engineer
A concurrency engineer specializes in designing and implementing software that can perform multiple tasks simultaneously and efficiently. This course is extremely helpful to anyone in this role, because it deals directly with the fundamental concepts and practical implementations of managing concurrent tasks using threads. The detailed exploration of thread synchronization, deadlocks, and mutual exclusion that this course provides is directly applicable to the daily work of a concurrency engineer. This course will allow one to develop the skills to build complex, concurrent systems.
Operating Systems Developer
An operating systems developer is deeply involved with the creation and maintenance of the core software that manages computer hardware and software resources. This role requires a strong understanding of multithreading, concurrency, and thread synchronization, all of which are covered in this course. The course provides a practical look at Pthreads on Linux, and includes extensive discussion of concepts like deadlocks, mutual exclusion, and condition variables, directly applicable to the challenges of OS development. Those working in this role should take this course to build a robust understanding of thread management at a low level.
Systems Programmer
Systems programmers work closely with the underlying architecture of computers, writing software and tools that support the operation of higher-level applications. This often involves dealing with multithreading and managing resources at a lower level. This course's emphasis on Pthreads on Linux provides a very practical education in handling threads, and is directly applicable to the work of a systems programmer. The course covers synchronization techniques, race conditions, and deadlocks, all common issues that one faces in this role. Gaining a deep understanding of thread management as taught in this course is very helpful in this career path.
Embedded Systems Engineer
Embedded systems engineers design, develop, and test software that powers devices like medical equipment, automotive systems, and industrial machinery. This career often involves working with real-time operating systems, and multithreading is a critical concept in these systems. This course helps build a foundation for developing more reliable and efficient software that can handle multiple tasks concurrently. It specifically explores thread creation, cancellation, and synchronization through practical examples using Pthreads, directly enhancing the skills needed in this field. The hands-on approach of this course will greatly assist those seeking to enhance their capabilities with low-level thread management.
Real-Time Software Engineer
Real time software engineers develop software for systems that must respond to actions instantly and predictably, often in industrial or scientific applications. Multithreading is extremely common in real time systems, because these systems must handle multiple inputs and outputs concurrently. This course, which focuses on thread synchronization, thread cancellation, and resource management, helps build a foundation for anyone who wants to excel in this role. Additionally, the course work with Pthreads provides a very useful, low-level perspective. Gaining familiarity with practical aspects of thread programming is critical for real-time systems, making this course a useful learning tool.
High-Performance Computing Engineer
High performance computing engineers work on designing and optimizing software for systems that tackle complex problems requiring massive computational power. The course's emphasis on multithreading and thread synchronization is directly relevant to creating highly efficient and scalable applications in high performance settings. This role often involves dealing with parallel processing and managing numerous threads efficiently to maximize system resources. This course covers the fundamental concepts of thread management in great detail, a critical skill for anyone wanting to work in high performance computing. The practical approach to thread management is highly valuable in this field.
Game Engine Programmer
Game engine programmers develop the underlying systems that power video games. These systems need to handle multiple tasks simultaneously, such as rendering graphics, managing game logic, and processing user input. This course helps build the fundamental skills in multithreading and synchronization needed to create responsive and smooth gaming experiences. A game engine programmer will benefit from gaining an understanding of thread creation, communication, and cancellation which are covered in great detail, allowing for the design of robust and efficient game engines. The focus on practical implementation makes the course highly relevant for this career.
Middleware Developer
A middleware developer builds software that acts as a bridge between different applications or systems, enabling them to communicate and exchange data. This role requires a comprehensive grasp of multithreading and concurrent programming, something that is directly addressed in this course. The course’s content on thread synchronization, communication, and the management of shared resources is very relevant to the work of a middleware developer. The hands-on approach to exploring thread management techniques makes this course very useful for those wanting to focus on robust and efficient middleware solutions.
Network Software Engineer
Network software engineers develop the software that makes computer networks function effectively. This often involves dealing with multiple simultaneous connections and data streams. This course, with its focus on multithreading fundamentals and thread synchronization using Pthreads, is a great resource for anyone in this field. The detailed exploration of concurrency, communication between threads, and race conditions is extremely relevant to the kind of software that a network software engineer builds. The course's content helps a network software engineer improve and maintain network performance and reliability.
Cloud Computing Engineer
A cloud computing engineer focuses on designing, implementing, and managing systems that leverage cloud infrastructure. Cloud systems rely heavily on multithreading to handle concurrent requests of many users, so this course is a great resource for anyone in this role. The course's practical exploration of Pthreads on Linux, along with the detailed study of thread synchronization and handling of shared resources, helps a cloud computing engineer build scalable and robust applications. The course helps build a foundation in a technology that is very relevant to this field.
Database Engineer
Database engineers design, implement, and maintain the databases that store and manage an organization's data. Modern databases utilize multithreading extensively to handle numerous concurrent requests from users. The course helps build a knowledge base on thread synchronization, mutual exclusion, and avoiding deadlocks, all essential for managing database performance, reliability, and consistency. This course's exploration of fundamental threading concepts makes it helpful for anyone who wants to be a database engineer.
Device Driver Developer
Device driver developers write the software that allows a computer's operating system to communicate with hardware devices. This role often involves writing low level code that must be highly efficient, and often requires multithreading. This course, which provides a foundation in multithreading concepts, helps anyone who wants to work with writing device drivers, which often need to operate concurrently. The course's focus on Pthreads on the Linux platform is directly relevant; because drivers often require low-level control, this course will help build confidence in anyone exploring this career. The low level focus of this course may be helpful in this role.
Application Software Developer
Application software developers create software that users interact with directly, and they may need to use multithreading in some cases to improve performance and responsiveness. While not all applications require it, this course helps application developers who may need to implement more advanced features and optimizations through multithreading. Understanding thread management, communication, and synchronization, as taught by this course, is very useful for an application software developer when designing more complex software. The course may be useful for those working on software requiring parallel processing or that must respond to multiple inputs concurrently.
Software Architect
Software architects are responsible for the high-level design of software systems, making decisions about how different components interact. This course may be helpful for a software architect in that it familiarizes them with the fundamentals of multithreading, concurrency, and thread synchronization, which inform their design decisions, especially on how to build performant systems. The detailed study of different synchronization methods and the challenges of concurrent programming may be useful for any software architect designing more complex systems. This course may be useful for those who work on systems utilizing multiple threads.
Technical Lead
A technical lead oversees a team of developers, and needs a deep understanding of the technical aspects of the software they are responsible for, in order to be effective. This course may be useful for a technical lead, because understanding multithreading and synchronization is critical in designing and reviewing the work produced by their team. The course’s exploration of thread management, deadlocks, and resource management can be useful to a technical lead when leading a team working on multithreaded applications. The low level focus of this course may enhance the capability of a technical lead.

Reading list

We've selected two books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Part A - Multithreading & Thread Synchronization - Pthreads.
Comprehensive guide to POSIX threads, covering everything from basic thread creation to advanced synchronization techniques. It provides detailed explanations and practical examples of how to use pthreads effectively. This book is commonly used as a reference by industry professionals. It adds depth to the course by providing a more in-depth look at the pthreads API.
Provides a comprehensive overview of UNIX system programming, including detailed coverage of threads and concurrency. It offers valuable insights into the underlying mechanisms and best practices for multithreaded programming. This book is commonly used as a textbook at academic institutions and by industry professionals. It adds breadth to the course by providing a broader context for multithreading within the UNIX environment.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Similar courses are unavailable at this time. Please try again later.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser