Professional Documents
Culture Documents
Lecture No. 09
OPERATING SYSTEMS 3
Single–Threaded Process
• Main ()
• {
• …
• f1 (…);
• …
• f2(…);
• …
• }
• f1(…..)
• {…}
• f2(…)
• {…}
OPERATING SYSTEMS 4
Multi–Threaded processes
• Main()
• {
• …
• thread (t1,f1);
• …
• thread (t2,f2);
• …
• }
• f1(…)
• {…}
• f2(…)
• {…}
OPERATING SYSTEMS 5
User Threads
OPERATING SYSTEMS 6
User Threads
• Examples
POSIX Pthreads
Mach C-threads
Solaris 2 threads
OPERATING SYSTEMS 7
Kernel threads
OPERATING SYSTEMS 8
Kernel threads
• Examples
Windows NT/200
Solaris 2
Linux
OPERATING SYSTEMS 9
Multithreading Models
OPERATING SYSTEMS 10
Many-to-One Model
OPERATING SYSTEMS 11
Multithreading Models
• One-to-one: one user thread per kernel threads; process does not block
when thread makes a system call
• Overhead for creating a kernel thread per user thread
• True concurrency achieved
• Windows NT/2000, OS/2
OPERATING SYSTEMS 12
One-to-One Model
OPERATING SYSTEMS 13
Multithreading Models
OPERATING SYSTEMS 14
Many-to-Many Model
OPERATING SYSTEMS 15
Solaris 2 Threads Model
OPERATING SYSTEMS 16
Solaris 2 Threads Model
OPERATING SYSTEMS 17
Pthreads
• A POSIX standard ( IEEE 1003.1c) API for thread creation, termination, and
synchronization.
• API specifies the behavior of the thread library, implementation is up to
developers of the library.
• Common in UNIX operating systems.
OPERATING SYSTEMS 18
Creating a Thread
Where:
threadp The thread we are trying to create–thread ID (TID)
attr Used to modify the thread attributes ( stack size, stack
address,detached,joinable,priority,etc.)
OPERATING SYSTEMS 19
Error Handling
OPERATING SYSTEMS 20
Error Handling
OPERATING SYSTEMS 21
Joining a Thread
OPERATING SYSTEMS 22
THANKS