UMD CMSC 433 - Threads and Synchronization (89 pages)

Previewing pages 1, 2, 3, 4, 5, 6, 41, 42, 43, 44, 45, 46, 84, 85, 86, 87, 88, 89 of 89 page document View the full content.
View Full Document

Threads and Synchronization



Previewing pages 1, 2, 3, 4, 5, 6, 41, 42, 43, 44, 45, 46, 84, 85, 86, 87, 88, 89 of actual document.

View the full content.
View Full Document
View Full Document

Threads and Synchronization

81 views

Other


Pages:
89
School:
University of Maryland, College Park
Course:
Cmsc 433 - Programming Language Technologies and Paradigms
Programming Language Technologies and Paradigms Documents

Unformatted text preview:

CMSC 433 Programming Language Technologies and Paradigms Fall 2007 Threads and Synchronization October 11th 2007 thanks to Doug Lea for some slides Overview What are threads Concept Basic Java mechanisms Thread concerns Safety and Liveness Use of synchronization and signalling Threading design patterns 2 Computation Abstractions CPU 1 CPU 2 t1 t1 t4 t2 t2 p1 t3 p2 A computer t1 t5 p3 Threads p4 Processes e g JVM s 3 Processes vs Threads int x foo x int x foo x Processes do not share data int x foo x foo x Threads share data within a process 4 So What Is a Thread Conceptually it is a parallel computation occurring within a process Implementation view it s a program counter and a stack The heap and static area are shared among all threads All programs have at least one thread main 5 Why Multiple Threads Performance Parallelism on multiprocessors Concurrency of computation and I O Can easily express some programming paradigms Event processing Simulations 6 Why Not Multiple Threads Complexity Dealing with safety liveness composition Nondeterminism Even with correct code timing differences may result in different output each time it is run Not necessarily bad just makes it a pain to test 7 Programming Threads Threads are available in many languages C C Objective Caml Java SmallTalk In many languages e g C and C threads are a platform specific add on Not part of the language specification Part of the Java language specification 8 Java Threads Every application has at least one thread The main thread started by the JVM to run the application s main method The code executed by main can create other threads Explicitly using the Thread class Implicitly by calling libraries that create threads as a consequence RMI AWT Swing Applets etc 9 Java Threads Creation To explicitly create a thread Instantiate a Thread object An object of class Thread or a subclass of Thread Invoke the object s start method This will start executing the Thread s run method concurrently with the current



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Threads and Synchronization 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 Threads and Synchronization 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?