Introduction to Concurrency Kenneth M Anderson University of Colorado Boulder CSCI 5828 Lecture 4 01 21 2010 University of Colorado 2010 1 Credit where Credit is Due 2 Some text and images for this lecture come from the lecture materials provided by the publisher of the Magee Kramer optional textbook As such some material is copyright 2006 John Wiley Sons Ltd Lecture Goals Review material in Chapter 1 of the Breshears textbook Who wants to go faster Raise your hand if you want to go faster Threading Methodologies Parallel Algorithms Intro Cover remainder of Chapter 1 material in Lecture 6 3 Why worry 4 Concurrency is hard and I ve only ever needed singlethreaded programs Why should I care about it Answer multi core computers increasing use of clusters Growth rates for chip speed are flattening lets wait a year and our system will run faster No longer Instead chips are becoming wider more cores wider bus more data at a time more memory As chips are not getting faster the same way they used to a single threaded single process application is not going to see any significant performance gains from new hardware New Model Instead software will only see performance gains with new hardware if they are designed to get faster the more processors they have available This is not easy the computations that an application performs have to be amenable to parallelization Such an application will see noticeable speed improvements when run on machines with more processors 2 cores 4 cores 8 cores becoming standard Intel 80 cores A system written for n cores could potentially see an 80x speed up when run on such a machine very hard to achieve linear speed ups however 5 In addition Concurrent programming is becoming hard to ignore In addition to the increasing presence of multi core computers there are lots of other domains in which concurrency is the norm Embedded software systems robotics command andcontrol high performance computing use of clusters Web programming often requires concurrency AJAX Web browsers examples of multi threaded GUI applications without threads the UI would block as information is downloaded 6 BUT While concurrency is widespread it is also error prone Programmers trained on single threaded programs face unfamiliar problems synchronization race conditions deadlocks etc Example Therac 25 Concurrent programming errors contributed to accidents causing death and serious injury Mars Rover Problems with interaction between concurrent tasks caused periodic software resets reducing availability for exploration 7 Basics Single Thread Single Process Single Machine Thread Data Code Process Machine Sequential Program Single Thread of Control 8 Basics Multiple Thread Single Process Single Machine Thread Thread Data Code Process Machine Concurrent Program Multiple Threads of Control 9 Multi Thread But is it truly parallel Thread Thread Data Code We may have multiple threads in this process but we may not have events truly occurring in parallel Why not It depends on the machine If the machine has multiple processors then true parallelism can Machine occur Otherwise parallelism is simulated Concurrent Program Multiple Threads of Control Process 10 Basics Single Thread Multiple Process Single Machine Thread Thread Data Code Process Thread Data Code Process Data Code Process Machine 11 Basics Multi thread Multi Process Single Machine Thread Thread Data Code Process Thread Thread Data Code Process Thread Thread Data Code Process Machine Note You can have way more than just two threads per process 12 Basics Multi everything Thread Thread Data Code Thread Thread Data Code Process Thread Thread Data Code Process Process Machine Thread Thread Data Code Process Thread Thread Data Code Process Thread Thread Data Code Process Machine 13 Applications are Dead Long Live Applications Due to the ability to have multiple threads multiple processes and multiple machines work together on a single problem the notion of an application is changing It used to be that Thread Application Data Code Process 14 Now we might refer to this as an application Multiple Thread Single Process Single Machine Thread Basics Multiple Thread Single Process Single Machine Thread Thread Data Code Thread Data Code Process Process Machine Machine multi threaded client multi threaded server that in turn relies on a cluster of machines to service the request 6 For instance we might call this Google 6 Data Code Data Code Data Code Data Code Data Code Data Code Data Code Data Code Data Code Process Process Process Data Code Data Code Data Code Process Process Process Data Code Data Code Data Code Process Process Process Data Code Data Code Data Code Process Process Process Data Code Data Code Data Code Process Process Process Data Code Data Code Data Code Process Process Process Data Code Data Code Data Code Process Process Process Data Code Data Code Data Code Process Process Process Process Process Process Process Process Process Machine Machine Machine Machine Machine Machine Machine Machine Machine Machine 15 Architecture Design Choices 16 When designing a modern application we now have to ask How many machines are involved What components will be deployed on each machine For each component Does it need concurrency If so will we achieve concurrency via multiple threads multiple processes both Consider Chrome I 17 Google made a splash last year by announcing the creation of a new web browser that is multi process one process per tab and multi threaded multiple threads handle loading of content within each process In typical Google style they documented their engineering choices via a comic book http www google com googlebooks chrome index html Consider Chrome II Some of the advantages they cite for this design stability single process multi threaded browsers are vulnerable to having a crash in one tab bring down the entire browser speed multi process browsers can be more responsive due to OS support security exploits in single process browsers are easier if malware loaded in one tab can grab information contained in another tab much harder to grab information across processes 18 Chrome Demo We can use process monitoring capabilities to verify that Chrome is indeed multi process and multi threaded Demo 19 Other benefits to multiprocess design 20 Lots of existing applications that do useful things Think of all the powerful command line utilities found in Unixbased platforms You can take advantage of that power in your own application
View Full Document
Unlocking...