0% found this document useful (0 votes)
1 views

Operating Systems 8

Uploaded by

hussainmalaika36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Operating Systems 8

Uploaded by

hussainmalaika36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Operating

Systems
Lecture 7
Agenda for Today
 Single-and multi-threaded
process
 Thread models
 User and kernel threads
 Pthreads library with examples
 Recap of lecture
Single-Threaded Process
main()
{ Thread

f1(…);
… f1
f2(…);

}
f2
f1(…)
{ … }
f2(…)
{ … } Process
Terminated
Multi-Threaded Process
main()
{ Process Address Space

thread(t1,f1); main t1 t2

thread(t2,f2); PC

PC
}
f1(…) PC
{ … }
f2(…)
{ … }
User Threads
Thread management done by user-
level threads libraries
 Kernel not aware of threads
 CPU not interrupted during thread
switching
 A system call by a thread blocks the
whole process
 Fair scheduling: P1 has one thread and
P2 has 100 threads
User Threads
Examples
POSIX Pthreads
Mach C-threads
Solaris 2 threads
Kernel Threads
Thread management done by
kernel
Kernel aware of threads
CPU switched during context
switching
A system call does not block the
whole process
Fair scheduling: P1 has one thread
and P2 has 100
Kernel Threads
Examples
Windows NT/2000
Solaris 2
Linux
Multithreading Models
Support for both user and kernel
threads
Many-to-One: Many user threads
per kernel thread; process blocks
when a thread makes a system call
Solaris Green threads
Pthreads
Many-to-One Model

User–level
Threads

Kernel–level
Thread
Multithreading Models
One-to-One: One user thread per
kernel thread; process does not block
when a thread makes a system call
Overhead for creating a kernel thread
per user thread
True concurrency achieved
Windows NT/2000, OS/2
One-to-One Model
P1 P2

User–level
Threads

Kernel–level
Threads
Multithreading Models
 Many-to-Many: Multiple user threads
multiplexed over a smaller or equal number of
kernel threads
 True concurrency not achieved because kernel
can only schedule one thread at a time
 Kernel can schedule another thread when a
user thread makes a blocking system call
 Solaris 2, HP-UX
Many-to-Many Model
P1 P2 P3

User–level
Threads

Kernel–level
Threads
Solaris 2 Threads Model
Solaris 2: threads, light-weight
processes (LWPs), and processes
At least one LWP per process to
allow a user thread to talk to a
kernel thread
User level threads switched and
scheduled among LWPs without
kernel’s knowledge
Solaris 2 Threads Model
One kernel thread per LWP; some
kernel threads have no LWP (e.g.,
threads for clock interrupt handler
and scheduling)
Solaris 2 Threads Model

© Copyright Virtual University of Pakistan

You might also like