CMSC 433 Lecture Notes - Lecture 17: Java Memory Model, Java Concurrency, Concurrency Control
Document Summary
Why concurrency: performance if the can do operations simultaneously, applications run faster, availability computing intensive parts of application need not slow down other parts, application demands many applications feature concurrency as part of system design. Concurrency is hard (to debug, optimize, and test), why: nondeterminism executing same program can yield diff answers. Nondeterminism: we have shared field that is initialized to 0. Two threads t1, t2 with instance variables myshared. If you ran t1. start() and t2. start() to start the threads where each start() is conceptually a single operation, procedural abstraction breaks. The only answer should be 2 but it can be 1 or 2. Java memory model: stack local variables & method parameters, heap objects (every call to new allocated space on heap, class-typed variables reference heap or null. More on main memory (mm: naively, mm is a table where each address can store a value and each address refers to one memory location (no copies)