Course 20026 Advanced Programming Concepts

Homework course module 1

Eating and Thinking Philosophs (3 points)

E. Dijkstra intoduces the problem of the eating and thinking philosophs already in 1971. This describes a standard problem in the area of distibuted computing systems. It should show problems with the mutual allocation of ressources to autonomous acting components of distributed systems.

Suggest there are sitting six philosophs around a table, in which middle a bowl of eating stands. A philosoph can mutual either think or eat. Further there are only six forks available. Thereby one fork is always between two neighboring philosophs, but they need two forks to eat. That is to say that at one time only the middle philosph of three can eat due to the fact that two neighboring philosophs share one fork in their middle.

Question: How many philosophs can eat at the same time? Please reason your answer!

Threads (12 points)

Gisela and Klaus own an account with 100 EUR deposit together. They want to withdraw some money at the same day and at different locations. They proceed as follows:

Gisela
Query balance
Withdraw 60 EUR

Klaus
Query balance
Withdraw 70 EUR

At the account isn't established any credit facility, i. e. that money can only be drawn if there is a sufficient deposit. Suggest, the programmer of the teller machine's software has learned Java recently; he hasn't heard anything about critical areas.

Please determine, which deposit the mutual account may have after the execution of the given activities. How much money get Klaus and Gisela in which case? Which deposit is seen at the time of their queries? Please reason your answer!

Precedence Graph (15 points)

The following arithmetical expression of programming language JAVA is given:

A = B * C++ + (-A--) * C / D

There are the following instructions:

Befehl
Bedeutung
L(A) reads variable A
S(A) writes variable A
Op(*) executes the operation * (multiplication)

There are appropriate instructions concerning all variables and operations. For example, the precedence graph for the expression C = A + B looks like the following:

a) Construct the precedence graph matching the expression above! (10 points)

b) Declare, how much time units are needed to compute that expression when the advantage of concurrency is maximal used. Thereby one instruction needs one time unit. (5 points)