CS 3220: Operating Systems: Instructor
CS 3220: Operating Systems: Instructor
OPERATING SYSTEMS
LECTURE 2
INSTRUCTOR:
OSAMA AHMED KHAN
osamaahmedkhan MAR 18TH, 2020
THREADS
• A Process:
• has a unique Address Space, and
• has a Single Thread of Control/Execution
• might have Multiple Threads of Control sharing the same Address
Space (MiniProcesses), and the concept is known as
MultiThreading
THREAD USAGE
2. Spreadsheet
• Three Threads required
i. User Interaction
ii. Recomputing
iii. Backup
• Process Model
1. Resource Grouping
• Groups related resources to be managed efficiently
2. Execution
• Thread of Execution OR Thread possesses the following
components:
i. Program Counter: Keeps track of which instruction to execute next
ii. Registers: Holds current working variables
iii. Stack: Contains execution history, with one frame for each current
working procedure
iv. State: Running, Ready or Blocked
• All the components are stored in a Thread Table
THE CLASSICAL THREAD MODEL
THE CLASSICAL THREAD MODEL
THE CLASSICAL THREAD MODEL
Process:
{
Global Variables
Thread 1: Thread 2: …
{ {
Private Global Variables Private Global Variables
… …
Function 1: Function 1:
{ {
Local Variables Local Variables
… …
} }
Function 2: Function 2:
{ {
Local Variables Local Variables
… …
} }
}
}
THE CLASSICAL THREAD MODEL
POSIX THREADS
• Hybrid Implementation
• Kernel assigns a number of Virtual Processors (starting from
one) to each Process
• Run-time System in User Space allocates Threads to Virtual
Processors
• A Process can ask for more Virtual Processors and can also
return some if it no longer needs
• Kernel can also take back Virtual Processors assigned to a
Process, in order to assign them to more needy Processes
SCHEDULER ACTIVATIONS