04-Threads_2spp

04-Threads_2spp - CSE 421/521 - Operating Systems Fall 2011...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSE 421/521 - Operating Systems Fall 2011 Tevfik Ko ş ar University at Buffalo September 8 th , 2011 Lecture - IV Threads 2 Roadmap • Threads Why do we need them? Threads vs Processes Threading Examples Other Threading Issues • Thread cancellation • Signal handling • Thread pools • Thread specific data
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3 Concurrent Programming • In certain cases, a single application may need to run several tasks at the same time 1 1 2 3 2 4 5 3 4 5 sequential concurrent 4 Motivation • Increase the performance by running more than one tasks at a time. divide the program to n smaller pieces, and run it n times faster using n processors To cope with independent physical devices. do not wait for a blocked device, perform other operations at
Background image of page 2
Serial vs Parallel 5 Q Please COUNTER COUNTER 1 COUNTER 2 6 Divide and Compute x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 How many operations with sequential programming? 7 Step 1: x1 + x2 Step 2: x1 + x2 + x3 Step 3: x1 + x2 + x3 + x4 Step 4: x1 + x2 + x3 + x4 + x5 Step 5: x1 + x2 + x3 + x4 + x5 + x6 Step 6: x1 + x2 + x3 + x4 + x5 + x6 + x7 Step 7: x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
7 Divide and Compute x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 Step 1: parallelism = 4 Step 2: parallelism = 2 Step 3: parallelism = 1 8 Gain from parallelism In theory: dividing a program into n smaller parts and running on n processors results in n time speedup In practice: This is not true, due to Communication costs Dependencies between different program parts Eg. the addition example can run only in log(n) time not 1/n
Background image of page 4
9 Concurrent Programming • Implementation of concurrent tasks: as separate programs as a set of processes or threads created by a single program • Execution of concurrent tasks: on a single processor (can be multiple cores) ! Multithreaded programming on several processors in close proximity ! Parallel computing on several processors distributed across a network ! Distributed computing 10 Why Threads? In certain cases, a single application may need to run several tasks at the same time Creating a new process for each task is time consuming Use a single process with multiple threads • faster • less overhead for creation, switching, and termination • share the same address space
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Ownership vs Execution 11 " A process embodies two independent concepts: 1. resource ownership 2. 1. Resource ownership # a process is allocated address space to hold the image, and is granted control of I/O devices and files # the O/S prevents interference among processes while they make use of resources (multiplexing) 2. Execution & scheduling # a process follows an execution path through a program --> Thread # it has an execution state and is scheduled for dispatching Multi-threading 12 " The execution part is a “thread” Pasta for six boil 1 quart salty water
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 10/01/2011.

Page1 / 21

04-Threads_2spp - CSE 421/521 - Operating Systems Fall 2011...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online