Course contentsShow
← Computer Science
Lesson 1267 of 2,87229. CPU SchedulingFree lesson

Gang Scheduling

Learning how to schedule related threads simultaneously across multiple CPUs for coordinated parallel execution.

Gang Scheduling

What you'll learn: How to schedule groups of cooperating threads to run simultaneously on multiple CPUs so they can work together efficiently.

The Challenge of Parallel Teamwork

Imagine a relay race where all runners need to be on the track at the same time to pass the baton smoothly. If one runner is delayed, the whole team waits. In multiprocessor systems, some parallel applications have threads that frequently synchronize or communicate with each other. If these related threads run at different times, they spend more time waiting for each other than actually working.

What is Gang Scheduling?

Gang scheduling is a CPU scheduling strategy that schedules all threads belonging to the same parallel application (a "gang") to run simultaneously across multiple CPUs. Instead of treating each thread independently, the scheduler recognizes that certain threads work as a team and allocates CPU time to the entire group at once.

Think of it like scheduling a band practice: you don't want the drummer showing up at 2 PM, the guitarist at 3 PM, and the singer at 4 PM. You schedule the whole band at the same time so they can actually play music together.

How It Works

The scheduler divides time into scheduling slots and assigns whole gangs to run together during each slot. If a gang has four threads, the system allocates four CPUs simultaneously for that gang's time slice. When the time slice expires, all four threads are preempted together, and another gang gets its turn across the available CPUs.

This approach minimizes synchronization delays because threads don't waste time waiting for their partners to be scheduled—they're all running at the same time.

Key Takeaway: Gang scheduling coordinates the simultaneous execution of related threads across multiple CPUs, reducing wait time in tightly-coupled parallel applications where threads frequently communicate or synchronize.