Name (print *CLEARLY*): _________________________________________________


Student ID (print *CLEARLY*; 1 digit per underline): _____ _____ _____ _____ _____ _____

CSE 231s Quiz 19: Isolated and MutableInt Data Race

private static int x = 0;
public static void main(String[] args) {
    launchApp(() -> {
        finish(() -> {
            
// Block A
            async(() -> {
                isolated(() -> {
                    x = x + 2;
                });
            });
            
// Block B
            async(() -> {
                isolated(() -> {
                    x = x - 3;
                });
            });
            
// Block C
            async(() -> {
                x = x + 1;
            });
        });
        System.out.println(x);
    });
}

source: RiceX COMP 322 Fundamentals of Parallel Programming

1a) What can run in parallel with Block A? _____________________________

1b) What can run in parallel with Block B? _____________________________

1c) What can run in parallel with Block C? _____________________________

 

 

2) How many different ways can we serialize all the reads and writes to x?

Given the partial definition of MutableInt:

public  class  MutableInt extends Number implements Comparable<MutableInt>, Mutable<Number> {
   
/** The mutable value. */
    private int  value;

   
/**
     * Constructs a new MutableInt with the default value of zero.
     */

    public MutableInt() {
        super();
    }

    /**
     * Adds a value to the value of this instance.
     *
@param operand  the value to add, not null
     */
    public void add(final  int  operand) {
       
this.value += operand;
    }

    /**
     * Returns the value of this MutableInt as an int.
     *
@return the numeric value represented by this object after conversion to type int.
     */
    @Override
    public int intValue() {
       
return value;
    }
}

and this parallel program:

MutableInt total = new MutableInt();
finish(() -> {
    async(() -> {
       
total.add(11);
    });
   
 total.add(10);
});
System.
out.println(total.intValue());

 

3a) Is there a data race?

3b) If so, encircle all of the lines which contribute to the data race.