Name (print clearly): _________________________________________________
Student ID (print clearly; 1 digit per underline): _____ _____ _____ _____ _____ _____
CSE 231s Quiz 04: Data Races
1a) Is there is a data race in the code below? Yes / No
1b) If so, encircle all lines that contribute to the data race.
double
value
= 5;
finish(() -> {
async(() -> {
double
squareOfValue
=
value*value;
});
double
squareRootOfValue
= Math.sqrt(value);
});
2a) Is there is a data race in the code below? Yes / No
2b) If so, encircle all lines that contribute to the data race.
double[]
array
= { 5 };
finish(() -> {
async(() -> {
double
squareOfValue
=
array[0]*array[0];
});
double
squareRootOfValue
= Math.sqrt(array[0]);
});
3a) Is there is a data race in the code below? Yes / No
3b) If so, encircle all lines that contribute to the data race.
double[]
array
= { 5 };
finish(() -> {
async(() -> {
array[
0 ]++;
});
array[
0 ]++;
});
4a) Is there is a data race in the code below? Yes / No
4b) If so, encircle all lines that contribute to the data race.
double[]
array
= { 5 };
finish(() -> {
async(() -> {
array[
0 ] =
array[
0 ] + 1;
});
array[
0 ] =
array[
0 ] + 1;
});
For the code below which determines if pattern is found in text:
5a) Is there a Data Race? (Yes/No) ____________
5b) Is it Functionally Deterministic? (Yes/No) ____________
5c) Is it Structurally Deterministic? (Yes/No) ____________
5d) If is is NOT Structurally Deterministic, tightly encircle the lines which make it so.
boolean
searchPar(char[] pattern,
char[] text)
{
int
M
=
pattern.length;
int
N
= text.length;
boolean[] found
= {
false
};
finish(() -> {
for
(int
i
= 0; i
<= N
- M;
i++)
{
if
(found[0])
{
break;
}
final
int
ii
= i;
async(() -> {
int
j;
for
(j
= 0; j
< M;
j++)
{
doWork(1);
if
(text[ii
+ j]
!=
pattern[j])
{
break;
}
}
if
(j
== M)
{
found[0]
=
true;
}
});
}
});
return
found[0];
}