276x Filetype PDF File size 0.30 MB Source: user.it.uu.se
UppsalaUniversity
ThreadprogrammingwithPOSIXThreads
(Pthreads)
Karl Ljungkvist
UppsalaUniversity
Whatarethreads?
Definition:
◮ Independentstreamsofinstructions within a single
program,whichcanbescheduledindependentlyby
the OS
In practice:
◮ Athreadisaprocedure/functionrunning
independently from the main program.
◮ Awayofutilizing multiple cores.
Lightweight process:
◮ Only duplicates a necessary minimal
◮ Mostresources are shared within the process
◮ Less overhead
Karl Ljungkvist | karl.ljungkvist@it.uu.se | 2/45
UppsalaUniversity
Processes vs Threads
Processes: Threads:
◮ Multiple instances of the ◮ Single program with
sameprogram,which parallel internal threads
cancommunicateby sharing resources
messagepassing (memory,openfiles,etc)
Core 0 a.out a.out
Core 0 t0
Core 1 a.out Core 1 t1
Core 2 a.out Core 2 t2
Core 3 a.out Core 3 t3
Karl Ljungkvist | karl.ljungkvist@it.uu.se | 3/45
UppsalaUniversity
Sharedresources
Athreadcontainsprivate In addition, a Unix process
◮ Programcounter also has
◮ Registers and stack pointer ◮ Process, process group, user, and
◮ Schedulingproperties (i.e. policy groupIDs
andpriority) ◮ Environment
◮ Setofpendingandblocked ◮ Workingdirectory
signals ◮ Programinstructions
◮ StackandHeap
◮ File descriptors
◮ Signal actions
◮ Sharedlibraries
◮ Inter-process communication
Lightweight process tools
◮ Process to thread creation overhead ∼ 10:1
Karl Ljungkvist | karl.ljungkvist@it.uu.se | 4/45
no reviews yet
Please Login to review.