Unformatted text preview:

Why concurrent programming?EvolutionDefinitionsConcurrent languagesProblems with concurrencyProcess InteractionsSynchronizationExampleConcurrency in JavaJava Thread Life Cycle (Deitel & Deitel)Concurrency 1. Why concurrent programming?.................................. 2 2. Evolution..................................................................... 2 3. Definitions................................................................... 4 4. Concurrent languages.................................................. 6 5. Problems with concurrency......................................... 6 6. Process Interactions .................................................... 8 7. Synchronization ........................................................ 14 8. Example .................................................................... 17 9. Concurrency in Java.................................................. 20 10. Java Thread Life Cycle (Deitel & Deitel)................. 21 11. Why concurrent programming? • Performance • Throughput • Utilization of system resources 2. Evolution • Single user system: o First systems supported one single activity at a time. o Late 1950s - One general-purpose processor and one or more special-purpose processors for input and output operations • Multiprocessing systems: These systems use the CPU while an input/output operation is being performed. Note that programmers cannot control this task explicitly. • Multitasking systems: These systems give the impression that there are several CPUs serving different users at the same time. Programmers cannot control task scheduling. This is done by the operating system. 2• Multithreading systems: This is becoming very popular with Java. Programmers can split their programs into several threads and schedule them. • Multiprocessor systems: o These are systems with several processing elements (PEs) and programmers can concurrently use all these PEs. o Single-Instruction Multiple-Data (SIMD) machines:  The same instruction goes to all processors, each with different data - e.g., vector processors  Multiple-Instruction Multiple-Data (MIMD) machines: Independent processors that can be synchronized (unit-level concurrency) 33. Definitions • Concurrency or Parallelism? 9 Concurrency:  Logically simultaneous processing.  Does not require multiple processing elements  Requires interleaved execution on a single processing element. 9 Parallelism:  Physically simultaneous processing.  It does involve several processing elements. 9 Both concurrency and parallelism require controlled access to shared resources. 9 In general people use the word concurrent and parallel interchangeably. • A concurrent program: It is a program that has multiple threads or tasks of control allowing it perform multiple computations in parallel and to control multiple external activities that occur at the same time. • Processes: 9 A process is an operating system abstraction that allows once computer system to support many units of execution. 49 Each process typically represents a separate running program; for example, a web browser. 9 A process can generally be composed of one or several threads. • Threads: 9 A thread is a single sequential execution path in a program. 9 A thread is executed independently of other threads, while at the same time possibly sharing underlying system resources such as files, as well as accessing other objects constructed within the same program. 9 Every program has at least one thread 9 Threads subdivide the run-time behavior of a program into separate, independently running subtasks. 9 Every thread has its own:  stack,  priority, and  virtual set of registers. 54. Concurrent languages • Concurrent Pascal • Concurrent C • Communicating Sequential Processes (CSP) • Ada • Java • Etc. 5. Problems with concurrency • Non-deterministic: Unlike sequential programs, where programs are completely deterministic and their behavior can be reproducible, concurrent programs are likely to be highly non-deterministic. The order of execution of process in a concurrent program is unpredictable since it may be influenced by run-time conditions. • Speed-dependence: A sequential program is speed-independent because its correctness does not depend on the rate at which it is executed. However, a concurrent program may be speed-dependent. Its final output may depend on the relative speeds of execution of its component sequential processes. • Deadlock: Deadlock is a situation in which a set of processes are prevented from making any further progress by their mutually incompatible demands for additional resources. This can occur in a system of processes and resources iff the following conditions all hold together: 69 Mutual exclusion: processes are given exclusive access to the resources they acquire. 9 Wait and hold: processes continue to hold previously allocated resources while waiting for a new resource demand to be satisfied. 9 No preemption: resources cannot be removed from a process until it voluntarily releases them. 9 Circular wait: there may be a cycle of resources and processes in which each process is awaiting resources that are held by the next process in the cycle. • Starvation: This is the case where a process is prevented indefinitely from running by unfair scheduling. Fair scheduling ensures that no process needing a resource is indefinitely prevented from obtaining it by the demand from other processes. 76. Process Interactions • Definitions and Notations [D. Watt]: 9 Sequential processes:  Given two processes A and B, the sequential execution of A and B is denoted A;B, i.e., A is executed before B. 9 Collateral processes:  Given two processes A and B, the collateral execution of A and B is denoted A,B, i.e., the execution of A and B can be done in any order.  Example: m=7, n=n+1  Note that collateral processes are non-deterministic. 9 Parallel processes:  Given two processes A and B, the parallel execution of A and B is denoted A||B.  Note that A and B don’t have to be executed simultaneously.  Unlike sequential processes and collateral processes, A and B may need to interact. • Independent processes 9 Definition: Two processes A and B are independents if any component or any task Ai of A may be


View Full Document

GWU CSCI 210 - Concurrency

Download Concurrency
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Concurrency and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Concurrency 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?