Presentation is loading. Please wait.

Presentation is loading. Please wait.

Concurrency (2) CSE 132. Question The following four numbers are in 8-bit 2’s complement form: 00000000101010100101010111111111 Which order below represents.

Similar presentations


Presentation on theme: "Concurrency (2) CSE 132. Question The following four numbers are in 8-bit 2’s complement form: 00000000101010100101010111111111 Which order below represents."— Presentation transcript:

1 Concurrency (2) CSE 132

2 Question The following four numbers are in 8-bit 2’s complement form: 00000000101010100101010111111111 Which order below represents lowest to highest? A: 00000000 01010101 10101010 11111111 B: 10101010 11111111 00000000 01010101 C: 11111111 10101010 00000000 01010101 D: 11111111 00000000 01010101 10101010 E: none of the above

3 Synchronization Implicit “lock” associated with every object Synchronized methods acquire object’s lock prior to entering method and then release lock once method is complete Synchronized statement allows finer control (illustrated next) Either way, lock enforces mutual exclusion, only one thread at a time is allowed in “critical section,” or region of code controlled by lock

4 Synchronized statement public void addName(String name) { synchronized(this) { lastName = name; nameCount++; } nameList.add(name); } Argument is object whose lock is acquired Doesn’t synchronize add() method invocation

5 PropertyChangeSupport Bound properties – anonymous notification when a property’s value changes Properties are identified by strings – Must be identical for both publishers and subscribers Publishers indicate to PCS that property changed Subscribers are then notified of new property value Provides excellent observability for multi- threaded applications

6 Example Publishers – three RandomPerson objects Subscribers – interested in different properties about the publishers Properties – things persons are doing: – Walk “strolling” – TV “watching TV” – Nap “snoozing” – Guitar “playing guitar”

7 Dining Philosophers Five silent philosophers sit at a round table with bowls of rice. A chopstick is placed between each pair of adjacent philosophers. Each philosopher must alternately think and eat. Eating is not limited by the amount of rice left: assume an infinite supply. However, a philosopher can only eat while holding both the chopstick to the left and the chopstick to the right. Each philosopher can pick up an adjacent chopstick, when available, and put it down, when holding it. These are separate actions: chopsticks must be picked up and put down one by one. How do we design a concurrent algorithm such that each philosopher won't starve, i.e., can forever continue to alternate between eating and thinking.

8


Download ppt "Concurrency (2) CSE 132. Question The following four numbers are in 8-bit 2’s complement form: 00000000101010100101010111111111 Which order below represents."

Similar presentations


Ads by Google