Scheduling is the process of managing resources (mostly hardware resources like I/O, CPU, memory, etc.) effectively to complete a given set of tasks. Most of the methods of scheduling are process scheduling like First Come First Serve (FCFS), Shortest Job First (SJF), Round Robin (RR), etc. There are many tasks that require multiple processes or threads to work concurrently with each other–only one process working while others wait will jeopardize the system. Even executing one process and preemptive stop on the other can also result in jeopardizing the system.
What is a task ?
A Task is the smallest logical unit of work. A task can be made of multiple jobs. A job can a sub-task (similar to a task) or a process. All the jobs must work as a chunk in a specific order to complete a task. The jobs may be expected to run parallel or sequentially or a mix of both.
For example–Turning on a car. The driver must press clutch and brake, and then turn the key. All three processes must happen or else the car won’t start. In computer science, we can find a similar example in a neural network; weights of all the edges must be updated in one segment.
What is a gang ?
A gang means a task. So, gang scheduling is the scheduling of gangs in an efficient manner. The point which separates gang scheduling from other scheduling is that it considers a gang (task) as a quantum and schedules them. A gang might require either multiple processes or threads or a combination of both (threads and processes).
Gang scheduling uses an Outsterhout matrix as a data structure to facilitate all the scheduling tasks. It is a two-dimensional matrix where a row represents a time slice and a column represents a process or a thread.
P1 P2 P3 P4 P5 Time Slice 0 J1 J1 J1 J1 J1 Time Slice 1 J2 J2 J2 J2 J2 Time Slice 2 J3 J3 J4 J4 J4
The above table demonstrates how the Outsterhout matrix is formed and the jobs are scheduled. J1-J4 represents gangs and P1-P5 represents processes. Please note some literature also has processes in rows and time slices as columns.
As gang scheduling includes multiple processes and threads, there is a need for synchronization. Broadly there are two synchronization methods.
- Concurrent gang scheduling: The synchronization module orchestrates all the scheduling. All the gangs run for a specific time interval ‘t’ then it is interpreted and another gang can begin.
- SHARE scheduling system: Gangs with the same resource utilization are collected and executed for a fixed time period. The fixed period may change each time and the time is greater than equal to the minimum time of the tasks till which they can be non-preemptive.
Like process scheduling there are various types of scheduling gangs namely:
- Bag of gangs (BoG)
- Adapted first come first served (AFCFS)
- The largest gang first-served (LGFS)
- Paired gang scheduling
- Scheduling algorithm
Further details on gang scheduling types can be found at the LINK.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.