Introduction

Teaching team

Why concurrency?

Concurrency vs. Parallelism

Parallell programmering ≠ parallel programming

Course (general) goals

Practical course information

Gentle start

A summer job

Buy @ Cremona!

Free beer!

  final int buy_pause = 3000;
  final int beer_pause = 5000;
  int next_buy = buy_pause;
  int next_beer = beer_pause;
  ...

  buyThread = 
    new Thread() {
        public void run() { 
           while (true) {
              if (next_buy < next_beer) {
                 try { Thread.sleep(next_buy); }
                 catch (InterruptedException e) {} ;
                 window.flash("Buy @ Cremona"); 
                 next_beer = next_beer - next_buy;
                 next_buy = buy_pause;
              } 
              else if (next_buy > next_beer) {
                   try { Thread.sleep(next_beer); }
                   catch (InterruptedException e) {} ;
                   window.flash("Free beer!"); 
                   next_buy  = next_buy - next_beer ; 
                   next_beer = beer_pause ; 
              }
              else {
                 try { Thread.sleep(next_buy); }
                     catch (InterruptedException e) {} ;
                     window.flash("Buy @ Cremona! - Free beer!");
                     next_buy  = buy_pause ; 
                     next_beer = beer_pause ; 
             }
           }
         } 
       }
  

Java threads

Running Java threads

Napping in Java

Concurrent programming languages

Threads scheduling

Types of precess behaviour

Atomicity

Example: The Liseberg counter

What is the answer?

Terminology: States and traces

A bad trace


Turnstile East Turnstile West

counter = 0


    0:aload_0
1:dup
2:getfield #counter 5:iconst_1
6:iadd
    0:aload_0
1:dup
2:getfield #counter 5:iconst_1
6:iadd

counter = 0


    7:putfield #counter
    10:return

counter = 1


    7:putfield #counter 
    10:return

counter = 1

Program properties

Synchronisation

Critical sections

Mutual exclusion

Summary