05.08.2014 Views

here - Stefan-Marr.de

here - Stefan-Marr.de

here - Stefan-Marr.de

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3. Which Concepts for Concurrent and Parallel Progr. does a VM need to Support?<br />

1 object fairness {<br />

2 class FairActor () extends Actor {<br />

3 // ...<br />

4 <strong>de</strong>f act () { loop {<br />

5 react {<br />

6 case (v : int ) => { data = v }<br />

7 case ( wait ) => {<br />

8 // busy - waiting section<br />

9 if ( data > 0) println ( data )<br />

10 else self ! wait<br />

11 }<br />

12 case ( start ) => {<br />

13 calc ! (add , 4, 5)<br />

14 self ! wait<br />

15 }<br />

16 }}}}}<br />

Listing 3.2: Example for missing Scheduling Guarantees: Without the guarantee of<br />

fair scheduling, busy-waiting can starve other actors forever. [Karmani et al., 2009,<br />

Fig. 3]<br />

system from making progress. The example they give is shown in Lst. 3.2.<br />

Here the actor busy-waits by sending itself a message to await the arrival of<br />

the computation result. While the example is contrived, livelocks like this can<br />

be effectively avoi<strong>de</strong>d by fair scheduling.<br />

An ad hoc solution to these problems is the use of a lightweight task representation<br />

for actors, which is used to schedule these tasks on top of the threading<br />

mechanism provi<strong>de</strong>d by the VM to guarantee the <strong>de</strong>sired fairness property.<br />

To this end, the Java standard library provi<strong>de</strong>s the ExecutorServices 20<br />

and the CLI offers a TaskScheduler. 21<br />

Ad hoc solutions to enforce scheduling policies have limitations and introduce<br />

tra<strong>de</strong>offs. Since these solutions build on top of the VM’s thread<br />

abstraction, the provi<strong>de</strong>d guarantees are restricted. Computationally expensive<br />

operations and blocking primitives can bind the un<strong>de</strong>rlying thread. This<br />

restricts the ability of the scheduler to enforce the <strong>de</strong>sired guarantees, because<br />

as Karmani et al. note, the actor or task scheduler is prevented from<br />

running. It is possible to compensate to a certain <strong>de</strong>gree for such effects by<br />

20 http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorServic<br />

e.html<br />

21 http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler<br />

.aspx<br />

76

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!