Introduction to modelling in FSP (Finite State Processes) and its application for analysis of Java Mutex problems

Similar documents
CSCI 5828: Foundations of Software Engineering

Q1. From post-it note. Question asked after Prev. Lecture. thread life-cycle in Java. Q2. Concurrency and parallelism. Definitions

CSCI 5828: Foundations of Software Engineering

Shared Objects & Mutual Exclusion

Concurrent Execution

Shared Objects & Mutual Exclusion

CSCI 5828: Foundations of Software Engineering

Concurrent processes. Processes and Threads. A question asked by your friend. Warm-up exercises at beginning of Lecture 3. My question for you

Shared Objects & Mutual Exclusion

Processes & Threads. Concepts: processes - units of sequential execution.

Chapter 2. Processes & Threads. Concurrency: processes & threads 1. Magee/Kramer

CSCI 5828: Foundations of Software Engineering

Concurrent processes. Processes and Threads. Processes and threads. Going back to Concurrency. Modelling Processes. Modeling processes

Verification Finite-state process modeling and reachability analysis

Lecture 2: Modeling Introduction

Communications Software Engineering Analysis Model

Lecture 9: Introduction to Monitors

Chapter 9. Labelled Transition Systems. System Composition. specifications. implementations.

Communications Software Engineering Condition Synchronization and Liveness

THE QUEEN S UNIVERSITY OF BELFAST

COMP30112: Concurrency Topics 4.1: Concurrency Patterns - Monitors

Answer the first question and two further questions. i. action prefix ( -> ) [3 marks]

Concurrent Execution

LTSA User Manual.

Model Requirements and JAVA Programs MVP 2 1

7: Interprocess Communication

2. Concurrency and Java

FSP Language Specification

G52CON: Concepts of Concurrency

Dealing with Issues for Interprocess Communication

Monitors & Condition Synchronization

Chapter 6. Deadlock. DM519 Concurrent Programming

CSCI 5828: Foundations of Software Engineering

Synchronization I. Jo, Heeseung

Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Synchronization SPL/2010 SPL/20 1

Lecture 10: Introduction to Semaphores

Process Management And Synchronization

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

Ch 9: Control flow. Sequencers. Jumps. Jumps

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Monitors & Condition Synchronization

G52CON: Concepts of Concurrency

COMP 150-CCP Concurrent Programming. Lecture 12: Deadlock. Dr. Richard S. Hall

Safety & Liveness Properties

$ Program Verification

CONCURRENT PROGRAMMING - EXAM

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

Deadlock. INF2140 Parallel Programming: Lecture 6. March 07, INF2140 Parallel Programming: Lecture 6 Deadlock

Dept. of CSE, York Univ. 1

C340 Concurrency: Semaphores and Monitors. Goals

Synchronization I. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 6: Process Synchronization

Monitors & Condition Synchronisation

CS 153 Design of Operating Systems Winter 2016

Lesson 6: Process Synchronization

Monitors & Condition Synchronization

Synchronization Spinlocks - Semaphores

Agenda. Highlight issues with multi threaded programming Introduce thread synchronization primitives Introduce thread safe collections

Process Synchronization

IV. Process Synchronisation

Concurrent & Distributed Systems Supervision Exercises

Chapter 7: Process Synchronization. Background. Illustration

COMP 346 WINTER Tutorial 2 SHARED DATA MANIPULATION AND SYNCHRONIZATION

Lecture 5: Synchronization w/locks

Concurrency COMS W4115. Prof. Stephen A. Edwards Spring 2002 Columbia University Department of Computer Science

Implementing Coroutines. Faking Coroutines in Java

CHAPTER 6: PROCESS SYNCHRONIZATION

Real Time Operating Systems and Middleware

Chapter 7: Process Synchronization!

Concurrent Programming Lecture 10

Performance Throughput Utilization of system resources

Multithreaded Programming Part II. CSE 219 Stony Brook University, Department of Computer Science

! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

Sistemi in tempo reale Anno accademico

Chapter 7: Process Synchronization. Background

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

CS370 Operating Systems

1 Process Coordination

Last Class: Synchronization

Deadlock. Concepts: Models: Practice: Aim: deadlock avoidance - to design systems where deadlock cannot occur. Chapter 6. Deadlock

IT 540 Operating Systems ECE519 Advanced Operating Systems

G Programming Languages Spring 2010 Lecture 13. Robert Grimm, New York University

Monitors; Software Transactional Memory

Cache Coherence and Atomic Operations in Hardware

CS477 Formal Software Development Methods / 39

COMP30112: Concurrency Topics 5.2: Properties

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

CS Operating Systems

CS Operating Systems

Concurrent Processes Rab Nawaz Jadoon

Programming Language Concepts: Lecture 11

ECE 462 Object-Oriented Programming using C++ and Java. Scheduling and Critical Section

Generating Code from Event-B Using an Intermediate Specification Notation

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures

CMSC 132: Object-Oriented Programming II. Threads in Java

Transcription:

Introduction to modelling in FSP (Finite State Processes) and its application for analysis of Java Mutex problems MVP3 1

Modeling Processes Models are described using state machines, known as Labelled Transition Systems LTS. These are described textually as finite state processes (FSP) and displayed and analysed by the LTSA analysis tool. LTS - graphical form FSP - algebraic (textual) form MVP3 2

modeling processes A process is the execution of a sequential program. It is modeled as a finite state machine which transits from state to state by executing a sequence of atomic actions. on 0 1 a light switch LTS off on off on off on off. a sequence of actions or trace MVP3 3

FSP - action prefix If x is an action and P a process then (x-> P) describes a process that initially engages in the action x and then behaves exactly as described by P. ONESHOT = (once -> STOP). once 0 1 ONESHOT state machine (terminating process) Convention: actions begin with lowercase letters PROCESSES begin with uppercase letters MVP3 4

FSP - action prefix & recursion Repetitive behaviour uses recursion: on SWITCH = OFF, OFF = (on -> ON), ON = (off-> OFF). 0 1 Substituting to get a more succinct definition: SWITCH = OFF, OFF = (on ->(off->off)). And again: SWITCH = (on->off->switch). MVP3 5 off

animation using LTSA The LTSA animator can be used to produce a trace. Ticked actions are eligible for selection. In the LTS, the last action is highlighted in red. on 0 1 MVP3 6 off

FSP - action prefix FSP model of a traffic light : TRAFFICLIGHT = (red->orange->green->orange -> TRAFFICLIGHT). LTS generated using LTSA: red orange green 0 1 2 3 Trace: orange red orange green orange red orange green MVP3 7

FSP - choice If x and y are actions then (x-> P y-> Q) describes a process which initially engages in either of the actions x or y. After the first action has occurred, the subsequent behavior is described by P if the first action was x and Q if the first action was y. Who or what makes the choice? Is there a difference between input and output actions? MVP3 8

FSP - choice FSP model of a drinks machine : DRINKS = (red->coffee->drinks blue->tea->drinks ). LTS generated using LTSA: red blue 0 1 2 Possible traces? coffee tea MVP3 9

Non-deterministic choice Process (x-> P x -> Q) describes a process which engages in x and then behaves as either P or Q. COIN = (toss->heads toss->tails), HEADS= (heads->coin), toss TAILS= (tails->coin). Tossing a coin. toss 0 1 2 Possible traces? heads MVP3 tails 10

Modeling failure How do we model an unreliable communication channel which accepts in actions and if a failure occurs produces no output, otherwise performs an out action? Use non-determinism... in 0 1 in CHAN = (in->chan in->out->chan ). out MVP3 11

FSP - indexed processes and actions Single slot buffer that inputs a value in the range 0 to 3 and then outputs that value: BUFF = (in[i:0..3]->out[i]-> BUFF). equivalent to BUFF = (in[0]->out[0]->buff in[1]->out[1]->buff in[2]->out[2]->buff in[3]->out[3]->buff ). or using a process parameter with default value: BUFF(N=3) = (in[i:0..n]->out[i]-> BUFF). MVP3 12

FSP - constant & range declaration index expressions to model calculation: in.0.0 in.1.0 in.0.1 in.1.1 0 1 2 3 const N = 1 range T = 0..N range R = 0..2*N SUM = (in[a:t][b:t]->total[a+b]), TOTAL[s:R] = (out[s]->sum). out.0 MVP3 13 out.1 out.2

FSP - guarded actions The choice (when B x -> P y -> Q) means that when the guard B is true then the actions x and y are both eligible to be chosen, otherwise if B is false then the action x cannot be chosen. COUNT (N=3) = COUNT[0], COUNT[i:0..N] = (when(i<n) inc->count[i+1] when(i>0) dec->count[i-1] ). inc dec inc MVP3 14 inc 0 1 2 3 dec dec

FSP - guarded actions A countdown timer which beeps after N ticks, or can be stopped. COUNTDOWN (N=3) = (start->countdown[n]), COUNTDOWN[i:0..N] = (when(i>0) tick->countdown[i-1] when(i==0)beep->stop stop stop->stop ). stop stop start tick tick tick stop beep 0 1 2 3 4 5 MVP3 15

FSP - process alphabets The alphabet of a process is the set of actions in which it can engage. Alphabet extension can be used to extend the implicit alphabet of a process: WRITER = (write[1]->write[3]->writer) +{write[0..3]}. Alphabet of WRITER is the set {write[0..3]} (we make use of alphabet extensions in later chapters) MVP3 16

parallel composition - action interleaving If P and Q are processes then (P Q) represents the concurrent execution of P and Q. The operator is the parallel composition operator. ITCH = (scratch->stop). CONVERSE = (think->talk->stop). CONVERSE_ITCH = (ITCH CONVERSE). think talk scratch think scratch talk scratch think talk Possible traces as a result of action interleaving. MVP3 17

parallel composition - action interleaving ITCH scratch 0 1 2 states CONVERSE scratch think talk 0 1 2 3 states scratch CONVERSE_ITCH think talk scratch 0 1 2 3 4 5 from ITCH (0,0) (0,1) (0,2) (1,2) (1,1) (1,0) from CONVERSE 2 x 3 states MVP3 18 talk think

parallel composition - algebraic laws Commutative: (P Q) = (Q P) Associative: (P (Q R)) = ((P Q) R) = (P Q R). Clock radio example: CLOCK = (tick->clock). RADIO = (on->off->radio). CLOCK_RADIO = (CLOCK RADIO). LTS? Traces? Number of states? MVP3 19

modeling interaction - shared actions If processes in a composition have actions in common, these actions are said to be shared. Shared actions are the way that process interaction is modeled. While unshared actions may be arbitrarily interleaved, a shared action must be executed at the same time by all processes that participate in the shared action. MAKER = (make->ready->maker). USER = (ready->use->user). MAKER_USER = (MAKER USER). MAKER synchronizes with USER when ready. LTS? Traces? Number of states? MVP3 20

modeling interaction - handshake A handshake is an action acknowledged by another: MAKERv2 = (make->ready->used->makerv2). USERv2 = (ready->use->used ->USERv2). MAKER_USERv2 = (MAKERv2 USERv2). 3 states 3 states 3 x 3 states? make ready use 0 1 2 3 used 4 states Interaction constrains the overall behaviour. MVP3 21

modeling interaction - multiple processes Multi-party synchronization: MAKE_A = (makea->ready->used->make_a). MAKE_B = (makeb->ready->used->make_b). ASSEMBLE = (ready->assemble->used->assemble). FACTORY = (MAKE_A MAKE_B ASSEMBLE). makea makeb makea ready assemble 0 1 2 3 4 5 MVP3 makeb 22 used

composite processes A composite process is a parallel composition of primitive processes. These composite processes can be used in the definition of further compositions. MAKERS = (MAKE_A MAKE_B). FACTORY = (MAKERS ASSEMBLE). Substituting the definition for MAKERS in FACTORY and applying the commutative and associative laws for parallel composition results in the original definition for FACTORY in terms of primitive processes. FACTORY = (MAKE_A MAKE_B ASSEMBLE). MVP3 23

process labeling a:p prefixes each action label in the alphabet of P with a. Two instances of a switch process: SWITCH = (on->off->switch). TWO_SWITCH = (a:switch b:switch). a:switch a.on 0 1 b:switch b.on 0 1 a.off b.off An array of instances of the switch process: SWITCHES(N=3) = (forall[i:1..n] s[i]:switch). SWITCHES(N=3) = (s[i:1..n]:switch). MVP3 24

process labeling by a set of prefix labels {a1,..,ax}::p replaces every action label n in the alphabet of P with the labels a1.n,,ax.n. Further, every transition (n->x) in the definition of P is replaced with the transitions ({a1.n,,ax.n} ->X). Process prefixing is useful for modeling shared resources: RESOURCE = (acquire->release->resource). USER = (acquire->use->release->user). RESOURCE_SHARE = (a:user b:user {a,b}::resource). MVP3 25

process prefix labels for shared resources a:user a.acquire a.use 0 1 2 b:user b.acquire b.use 0 1 2 a.release How does the model ensure that the user that acquires the resource is the one to release it? RESOURCE_SHARE b.acquire a.acquire b.use {a,b}::resource b.release a.use 0 1 2 3 4 b.acquire a.acquire 0 1 a.release b.release b.release MVP3 26 a.release

action relabeling Relabeling functions are applied to processes to change the names of action labels. The general form of the relabeling function is: /{newlabel_1/oldlabel_1, newlabel_n/oldlabel_n}. Relabeling to ensure that composed processes synchronize on particular actions. CLIENT = (call->wait->continue->client). SERVER = (request->service->reply->server). MVP3 27

action relabeling CLIENT_SERVER = (CLIENT SERVER) /{call/request, reply/wait}. CLIENT call reply 0 1 2 SERVER call service 0 1 2 continue reply CLIENT_SERVER call service reply 0 1 2 3 continue MVP3 28

action relabeling - prefix labels An alternative formulation of the client server system is described below using qualified or prefixed labels: SERVERv2 = (accept.request ->service->accept.reply->serverv2). CLIENTv2 = (call.request ->call.reply->continue->clientv2). CLIENT_SERVERv2 = (CLIENTv2 SERVERv2) /{call/accept}. MVP3 29

action hiding - abstraction to reduce complexity When applied to a process P, the hiding operator \{a1..ax} removes the action names a1..ax from the alphabet of P and makes these concealed actions "silent". These silent actions are labeled tau. Silent actions in different processes are not shared. Sometimes it is more convenient to specify the set of labels to be exposed... When applied to a process P, the interface operator @{a1..ax} hides all actions in the alphabet of P not labeled in the set a1..ax. MVP3 30

action hiding The following definitions are equivalent: USER = (acquire->use->release->user) \{use}. USER = (acquire->use->release->user) @{acquire,release}. acquire tau 0 1 2 release Minimization removes hidden tau actions to produce an LTS with equivalent observable behavior. acquire 0 1 MVP3 31 release

structure diagrams P a b Process P with alphabet {a,b}. m P a b Q c c d x x x Parallel Composition (P Q) / {m/a,m/b,c/d} x P S a Q y Composite process S = (P Q) @ {x,y} MVP3 32

structure diagrams We use structure diagrams to capture the structure of a model expressed by the static combinators: parallel composition, relabeling and hiding. in TWOBUFF a:buff a.out in out in b:buff out out range T = 0..3 BUFF = (in[i:t]->out[i]->buff). TWOBUF =? MVP3 33

structure diagrams Structure diagram for CLIENT_SERVER? CLIENT call call request SERVER continue wait reply reply service Structure diagram for CLIENT_SERVERv2? CLIENTv2 call call accept SERVERv2 continue service MVP3 34

structure diagrams - resource sharing a:user printer b:user printer PRINTER_SHARE printer: RESOURCE acquire release RESOURCE = (acquire->release->resource). USER = (printer.acquire->use ->printer.release->user). PRINTER_SHARE = (a:user b:user {a,b}::printer:resource). MVP3 35

Shared Objects & Mutual Exclusion Concepts: process interference. mutual exclusion. Models: model checking for interference modeling mutual exclusion Practice: thread interference in shared Java objects mutual exclusion in Java (synchronized objects/methods). MVP3 36

Interference Ornamental garden problem: People enter an ornamental garden through either of two turnstiles. Management wish to know how many are in the garden at any time. Garden West Turnstile people East Turnstile The concurrent program consists of two concurrent threads and a shared counter object. MVP3 37

ornamental garden Program - class diagram Applet Thread Garden east,west Turnstile people Counter init() go() run() increment() eastd, westd, counterd NumberCanvas setvalue() display display The Turnstile thread simulates the periodic arrival of a visitor to the garden every second by sleeping for a second and then invoking the increment() method of the counter object. MVP3 38

ornamental garden program The Counter object and Turnstile threads are created by the go() method of the Garden applet: private void go() { counter = new Counter(counterD); west = new Turnstile(westD,counter); east = new Turnstile(eastD,counter); west.start(); east.start(); } Note that counterd, westd and eastd are objects of NumberCanvas used in chapter 2. MVP3 39

Turnstile class class Turnstile extends Thread { NumberCanvas display; Counter people; } Turnstile(NumberCanvas n,counter c) { display = n; people = c; } public void run() { try{ display.setvalue(0); for (int i=1;i<=garden.max;i++){ Thread.sleep(500); //0.5 second between arrivals display.setvalue(i); people.increment(); } } catch (InterruptedException e) {} } The run() method exits and the thread terminates after Garden.MAX visitors have entered. MVP3 40

Counter class class Counter { int value=0; NumberCanvas display; Hardware interrupts can occur at arbitrary times. } Counter(NumberCanvas n) { display=n; display.setvalue(value); } void increment() { int temp = value; //read value Simulate.HWinterrupt(); value=temp+1; //write value display.setvalue(value); } The counter simulates a hardware interrupt during an increment(), between reading and writing to the shared counter value. Interrupt randomly calls Thread.yield() to force a thread switch. MVP3 41

ornamental garden program - display After the East and West turnstile threads have each incremented its counter 20 times, the garden people counter is not the sum of the counts displayed. Counter increments have been lost. Why? MVP3 42

concurrent method activation Java method activations are not atomic - thread objects east and west may be executing the code for the increment method at the same time. west PC program counter shared code increment: read value write value + 1 east PC program counter MVP3 43

ornamental garden Model go end go end arrive value east: TURNSTILE go end arrive value west: TURNSTILE value:var read write GARDEN display Process VAR models read and write access to the shared counter value. Increment is modeled inside TURNSTILE since Java method activations are not atomic i.e. thread objects east and west may interleave their read and write actions. MVP3 44

ornamental garden model const N = 4 range T = 0..N set VarAlpha = { value.{read[t],write[t]} } VAR = VAR[0], VAR[u:T] = (read[u] ->VAR[u] write[v:t]->var[v]). The alphabet of process VAR is declared explicitly as a set constant, VarAlpha. TURNSTILE = (go -> RUN), RUN = (arrive-> INCREMENT end -> TURNSTILE), INCREMENT = (value.read[x:t] -> value.write[x+1]->run )+VarAlpha. GARDEN = (east:turnstile west:turnstile { east,west,display} ::value:var) /{ go /{ east,west}.go, end/{ east,west}.end}. The alphabet of TURNSTILE is extended with VarAlpha to ensure no unintended free actions in VAR ie. all actions in VAR must be controlled by a TURNSTILE. MVP3 45

checking for errors - animation Scenario checking - use animation to produce a trace. Is this trace correct? MVP3 46

checking for errors - exhaustive analysis Exhaustive checking - compose the model with a TEST process which sums the arrivals and checks against the display value: TEST = TEST[0], TEST[v:T] = (when (v<n){east.arrive,west.arrive}->test[v+1] end->check[v] ), CHECK[v:T] = (display.value.read[u:t] -> (when (u==v) right -> TEST[v] when (u!=v) wrong -> ERROR ) )+{display.varalpha}. Like STOP, ERROR is a predefined FSP local process (state), numbered -1 in the equivalent LTS. MVP3 47

ornamental garden model - checking for errors TESTGARDEN = (GARDEN TEST). Use LTSA to perform an exhaustive search for ERROR. Trace to property violation in TEST: go east.arrive east.value.read.0 west.arrive west.value.read.0 east.value.write.1 west.value.write.1 end display.value.read.1 wrong LTSA produces the shortest path to reach ERROR. MVP3 48

Interference and Mutual Exclusion Destructive update, caused by the arbitrary interleaving of read and write actions, is termed interference. Interference bugs are extremely difficult to locate. The general solution is to give methods mutually exclusive access to shared objects. Mutual exclusion can be modeled as atomic actions. MVP3 49

Mutual exclusion in Java Concurrent activations of a method in Java can be made mutually exclusive by prefixing the method with the keyword synchronized. We correct COUNTER class by deriving a class from it and making the increment method synchronized: class SynchronizedCounter extends Counter { } SynchronizedCounter(NumberCanvas n) {super(n);} synchronized void increment() { super.increment(); } MVP3 50

mutual exclusion - the ornamental garden Java associates a lock with every object. The Java compiler inserts code to acquire the lock before executing the body of the synchronized method and code to release the lock before the method returns. Concurrent threads are blocked until the lock is released. MVP3 51

Java synchronized statement Access to an object may also be made mutually exclusive by using the synchronized statement: synchronized (object) { statements } A less elegant way to correct the example would be to modify the Turnstile.run() method: synchronized(counter) {counter.increment();} Why is this less elegant? To ensure mutually exclusive access to an object, all object methods should be synchronized. MVP3 52

Modeling mutual exclusion To add locking to our model, define a LOCK, compose it with the shared VAR in the garden, and modify the alphabet set : LOCK = (acquire->release->lock). LOCKVAR = (LOCK VAR). set VarAlpha = {value.{read[t],write[t], acquire, release}} Modify TURNSTILE to acquire and release the lock: TURNSTILE = (go -> RUN), RUN = (arrive-> INCREMENT end -> TURNSTILE), INCREMENT = (value.acquire -> value.read[x:t]->value.write[x+1] -> value.release->run )+VarAlpha. MVP3 53

Revised ornamental garden model - checking for errors A sample animation execution trace go east.arrive east.value.acquire east.value.read.0 east.value.write.1 east.value.release west.arrive west.value.acquire west.value.read.1 west.value.write.2 west.value.release end display.value.read.2 right Use TEST and LTSA to perform an exhaustive check. Is TEST satisfied? MVP3 54

COUNTER: Abstraction using action hiding const N = 4 range T = 0..N VAR = VAR[0], VAR[u:T] = ( read[u]->var[u] write[v:t]->var[v]). LOCK = (acquire->release->lock). To model shared objects directly in terms of their synchronized methods, we can abstract the details by hiding. For SynchronizedCounter we hide read, write, acquire, release actions. INCREMENT = (acquire->read[x:t] -> (when (x<n) write[x+1] ->release->increment->increment ) )+{read[t],write[t]}. COUNTER = (INCREMENT LOCK VAR)@{increment}. MVP3 55

COUNTER: Abstraction using action hiding Minimized LTS: increment increment increment increment 0 1 2 3 4 We can give a more abstract, simpler description of a COUNTER which generates the same LTS: COUNTER = COUNTER[0] COUNTER[v:T] = (when (v<n) increment -> COUNTER[v+1]). This therefore exhibits equivalent behavior i.e. has the same observable behavior. MVP3 56

Typical efficiency measurement (of synchronized calls) double start = new Date().getTime(); for(long i = ITERATIONS; --i >= 0 ;) tester.locking(0,0); double end = new Date().getTime(); double locking_time = end - start; start = new Date().getTime(); for(long i = ITERATIONS; --i >= 0 ;) tester.not_locking(0,0); end = new Date().getTime(); double not_locking_time = end - start; double time_in_synchronization = locking_time - not_locking_time; MVP3 57

Synchronized calls are 7-8% slower than normal calls. Alternative to synchronization: value assignment Methods returning a simple value in a shared valiable, do not need synchronization due to the atomicity of assignment, e.g.: class some_class { int some_field; void f( some_class arg ) // deliberately no synchronized { } } //... some_field = new_value; // do this last. MVP3 58

Alternative to synchronization: priorities? According to JLS, threads may be assigned (10) different priorities. However, the effect is highly platform dependant! Solaris provides both cooperative (no implicit preemption) and preemptive thread execution, but without the users control. Windows provides only preemptive execution.terference bugs are extremely difficult to locate. MVP3 59

Typical execution platform MVP3 60

Summary Concepts process interference mutual exclusion Models model checking for interference modeling mutual exclusion Practice thread interference in shared Java objects mutual exclusion in Java (synchronized objects/methods). priorities do not offer predictable thread execution MVP3 61