1 / 14

CSCI 6900: Design, Implementation, and Verification of Concurrent Software

CSCI 6900: Design, Implementation, and Verification of Concurrent Software. Eileen Kraemer August 19 th , 2010 The University of Georgia. Concurrency Concepts . See: A tutorial we created . Java Threads & Concurrency. Liveness Deadlock Starvation and Livelock Guarded Blocks

israel
Download Presentation

CSCI 6900: Design, Implementation, and Verification of Concurrent Software

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 6900: Design, Implementation, and Verification of Concurrent Software Eileen Kraemer August 19th, 2010 The University of Georgia

  2. Concurrency Concepts • See: A tutorial we created ...

  3. Java Threads & Concurrency • Liveness • Deadlock • Starvation and Livelock • Guarded Blocks • Immutable Objects • A Synchronized Class Example • A Strategy for Defining Immutable Objects • High Level Concurrency Objects • Lock Objects • Executors • Executor Interfaces • Thread Pools • Concurrent Collections • Atomic Variables

  4. Deadlock • See example program “Deadlock”

  5. Starvation • describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. • happens when shared resources are made unavailable for long periods by "greedy" threads. • For example, suppose an object provides a synchronized method that often takes a long time to return. If one thread invokes this method frequently, other threads that also need frequent synchronized access to the same object will often be blocked.

  6. Livelock • A thread often acts in response to the action of another thread. If the other thread's action is also a response to the action of another thread, then livelock may result. • As with deadlock, livelocked threads are unable to make further progress. However, the threads are not blocked — they are simply too busy responding to each other to resume work.

  7. Guarded Blocks • Threads often have to coordinate their actions. • The most common coordination idiom is the guarded block. • block begins by polling a condition that must be true before the block can proceed. public void guardedJoy() { //Simple loop guard. Wastes processor time. Don't do this! while(!joy) { } System.out.println("Joy has been achieved!"); }

  8. More efficient guard • invoke Object.wait to suspend the current thread. • invocation of wait does not return until another thread has issued a notification that some special event may have occurred — though not necessarily the event this thread is waiting for – so wait inside a loop that checks the condition public synchronized guardedJoy() { //This guard only loops once for each special event, which may not //be the event we're waiting for. while(!joy) { try { wait(); } catch (InterruptedException e) {} } System.out.println("Joy and efficiency have been achieved!"); }

  9. wait public synchronized guardedJoy() { //This guard only loops once for each special event, which may not //be the event we're waiting for. while(!joy) { try { // owns the lock on this object wait(); // on call: release lock & suspend // on return: must re-aquire lock // before continuing } catch (InterruptedException e) {} } System.out.println("Joy and efficiency have been achieved!"); }

  10. notifyAll • While our first thread is waiting, some other thread will acquire the lock and invoke Object.notifyAll(), which informs all threads waiting on that lock that something “interesting” has happened public synchronized notifyJoy() { // obtains lock joy = true; notifyAll(); } // releases lock … at some point after this, the waiting thread re-acquires the lock

  11. notify vs. notifyAll • Notify wakes up one waiting thread, rather than all waiting threads

  12. Producer/ Consumer example • See: Drop example

  13. Assignment One • Create a producer/consumer system in which • the producer counts from 1 to 10, and places the current count into a shared object that you define. • The consumer reads the values from the shared object and displays them to the screen.

  14. Immutable Objects • state cannot change after it is constructed. • useful in concurrent applications. Since they cannot change state, they cannot be corrupted by thread interference or observed in an inconsistent state.

More Related