• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
13 concurrency
 

13 concurrency

on

  • 213 views

 

Statistics

Views

Total Views
213
Views on SlideShare
213
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    13 concurrency 13 concurrency Document Transcript

    • ICS 313 - Fundamentals of Programming Languages 113. Concurrency13.1 IntroductionConcurrency can occur at four levels:1. Machine instruction level2. High-level language statement level3. Unit level4. Program levelBecause there are no language issues in instruction and program-levelconcurrency, they are not addressed hereThe Evolution of Multiprocessor ArchitecturesLate 1950s - One general-purpose processor and one or more special-purpose processors for input and output operationsEarly 1960s - Multiple complete processors, used for program-levelconcurrencyMid-1960s - Multiple partial processors, used for instruction-levelconcurrencySingle-Instruction Multiple-Data (SIMD) machines. The same instructiongoes to all processors, each with different data - e.g., vector processorsMultiple-Instruction Multiple-Data (MIMD) machines - Independent processors thatcan be synchronized (unit-level concurrency)
    • ICS 313 - Fundamentals of Programming Languages 213.1 Introduction (continued)A thread of control in a program is the sequence of program pointsreached as control flows through the programCategories of ConcurrencyPhysical concurrency - Multiple independent processors(multiple threads of control)Logical concurrency - The appearance of physical concurrency ispresented by time-sharing one processor(software can be designed as if there were multiple threads of control)Coroutines provide only quasi-concurrencyReasons to Study ConcurrencyIt involves a different way of designing software that can be very useful- many real-world situations involve concurrencyComputers capable of physical concurrency are now widely used13.2 Intro to Subprogram-Level ConcurrencyA task is a program unit that can be in concurrent execution with otherprogram unitsTasks differ from ordinary subprograms in that:A task may be implicitly startedWhen a program unit starts the execution of a task, it is not necessarilysuspendedWhen a task’s execution is completed, control may not return to the callerTasks usually work togetherA task is disjoint if it does not communicate with or affect the executionof any other task in the program in any wayTask communication is necessary for synchronizationTask communication can be through:Shared nonlocal variablesParametersMessage passing
    • ICS 313 - Fundamentals of Programming Languages 313.2 Intro to Subprogram-Level Concurrency (continued)Kinds of synchronizationCooperationTask A must wait for task B to complete some specific activity before task A can continue its execution e.g., theproducer-consumer problemCompetitionWhen two or more tasks must use some resource that cannot be simultaneously used e.g., a shared counterCompetition is usually provided by mutually exclusive accessProviding synchronization requires a mechanism for delaying task executionTask execution control is maintained by a program called the scheduler, whichmaps task execution onto available processorsTasks can be in one of several different execution states:New - created but not yet startedRunnable or ready - ready to run but not currently running (no available processor)RunningBlocked - has been running, but cannot now continue (usually waiting for someevent to occur)Dead - no longer active in any sense13.2 Intro to Subprogram-Level Concurrency (continued)Liveness is a characteristic that a program unit may or may not haveIn sequential code, it means the unit will eventually complete its executionIn a concurrent environment, a task can easily lose its livenessIf all tasks in a concurrent environment lose their liveness, it is calleddeadlockDesign Issues for ConcurrencyHow is cooperation synchronization provided?How is competition synchronization provided?How and when do tasks begin and end execution?Are tasks statically or dynamically created?Methods of Providing Synchronization:SemaphoresMonitorsMessage Passing
    • ICS 313 - Fundamentals of Programming Languages 413.7 Java ThreadsThe concurrent units in Java are run methodsThe run method is inherited and overriden in subclasses ofthe predefined Thread classThe Thread ClassIncludes several methods (besides run)start, which calls run , after which control returns immediately tostartyield, which stops execution of the thread and puts it in the taskready queuesleep, which stops execution of the thread and blocks it fromexecution for the amount of time specified in its parameterEarly versions of Java used three more Thread methodssuspend, which stops execution of the thread until it is restarted with resumeresume, which restarts a suspended threadstop, which kills the thread13.7 Java Threads (continued)Competition Synchronization with Java ThreadsA method that includes the synchronized modifier disallows anyother method from running on the object while it is in executionIf only a part of a method must be run without interference, it can besynchronizedCooperation Synchronization with Java ThreadsThe wait and notify methods are defined in Object, which is the rootclass in Java, so all objects inherit themThe wait method must be called in a loopExample - the queueSee Queue class (pp. 549-550) and the Producer and Consumerclasses (p. 550)