Threads, Signals: Abhijit A M
Threads, Signals: Abhijit A M
Abhijit A M
abhijit.comp@coep.ac.in
Threads
thread — a fundamental unit of CPU utilization
A separate control flow within a program
set of instructions that execute “concurrently” with other parts of the code
Note the difference: Concurrency: progress at the same time, Parallel:
execution at the same time
Threads run within application
An application can be divided into multiple parts
Each part may be written to execute as a threads
Let’s see an example
Threads
Multiple tasks with the application can be implemented by separate
threads
Update display
Fetch data
Spell checking
Answer a network request
Process creation is heavy-weight while thread creation is light-weight, due
to the very nature of threads
Can simplify code, increase efficiency
Kernels are generally multithreaded
Single vs Mulththreaded process
A mulththreaded server
Benefits of threads
Responsiveness
Resource Sharing
Economy
Scalability
Single vs Multicore systems
Each user-level thread maps to kernel thread
Examples
Windows NT/XP/2000
Linux
Solaris 9 and later
Many-Many Model
Allows many user level
threads to be mapped to
many kernel threads
Allows the operating
system to create a
sufficient number of
kernel threads
Solaris prior to version 9
Windows NT/2000 with the
ThreadFiber package
Two Level Model
Similar to M:M, except
that it allows a user
thread to be bound to
kernel thread
Examples
IRIX
HP-UX
Tru64 UNIX
Solaris 8 and earlier
Thread Libraries
Thread libraries
Thread library provides programmer with
API for creating and managing threads
Two primary ways of implementing
Library entirely in user space
Kernel-level library supported by the OS
pthreads
May be provided either as user-level or kernel-level
A POSIX standard (IEEE 1003.1c) API for thread
creation and synchronization
API specifies behavior of the thread library,
implementation is up to development of the library
Common in UNIX operating systems (Solaris,
Linux, Mac OS X)
Demo of pthreads code