You are on page 1of 4

Threads Overview Definition: A thread, sometimes called a lightweight process (LWP), is a basic unit

of CPU utilization; it comprises a thread I , a program counter, a register set, and stac! "It shares with other threads belonging to the same process its code and signals"

Process: # traditional (or hea$%weight) process has s single thread of one tas! at a
time"

Single and Multithreaded Processes


&ingle threaded processes, it would be able to ser$ice onl% one client at time 'ultithreaded processes, it would be able to ser$ice se$eral of clients concurrentl% accessing it"

Per process items


#ddress space (lobal $ariable )pen files Child processes Pending alarms &ignals and signal handlers #ccounting information

Per thread items


Program counter *egisters &tac! &tatus +hread I

Benefits
," Responsiveness: 'ulti threading an interacti$e application ma% allow a program to continue running e$en if part of it us bloc!ed or is performing a length operating, thereb% increasing responsi$eness to the user" -or instance, a multithreaded web browser could still allow user interaction in one thread while an image is being loaded in another thread" ." Resource Sharing: /% default, threads share the memor% and the resources of the process to which the% belong" +he benefit of code sharing is that it allows an application to ha$e se$eral different threads of acti$it% all within the same address space" 0" Economy: #llocating memor% and resources for process creation is costl% "alternati$el%, because threads share resources of the process to which the% belong, it is more economical to create and conte1t switch threads" It can be difficult to gauge empiricall% the difference in o$erhead for creating and maintaining a process rather than a thread, but in general it is much more time consuming to create and mange processes than threads" 2" tili!ation of MP Architectures: "he benefits of multi threading can be greatl% increased in multiprocessor architecture, where each thread ma% be running in parallel on a different processor" # single3threaded process can onl% run on one CPU, no matter how man% are a$ailable" 'ultithreading on a multi3CPU machine increases concurrenc%"

ser "hreads
+hread management done b% user3le$el threads librar% +he librar% pro$ides support for thread creation, scheduling and management with no support of !ernel" +hree primar% thread libraries4 P)&I5 Pthreads , Win0. threads , 6a$a threads

#ernel "hreads
It is supported b% the operating s%stem" +he !ernel performs thread creation, scheduling and management in !ernel space" +hread management is done b% the operating s%stem, !ernel threads are slower to create and manage than are user threads" 71amples Windows 5P8.999 , &olaris , Linu1 +ru:2 U;I5 , 'ac )& 5

Multithreading Models

'an%3to3)ne )ne3to3)ne 'an%3to3'an% Many$to$One 'an% user3le$el threads mapped to single !ernel thread +hread management is done in user space, so it is efficient but the entire process will bloc! if a thread ma!es a bloc!ing s%stem call" E%amples: &olaris (reen +hreads , (;U Portable +hreads

One$to$One
7ach user3le$el thread maps to !ernel thread It pro$ides more concurrenc% than the man%3to one model b% allowing another thread to run when a thread ma!es a bloc!ing s%stem call" It allows multiple threads to run in parallel on 'ultiprocessors" Draw&ac': It is creating a user threads re<uires creating corresponding !ernel thread E%amples Windows ;+85P8.999 , Linu1 , &olaris = and later

Many$to$Many Model
#llows man% user le$el threads to be mapped to man% !ernel threads #llows the operating s%stem to create a sufficient number of !ernel threads &olaris prior to $ersion = , Windows ;+8.999 with the ThreadFiber pac!age