What is the likely result?

Give:

What is the likely result?

Give:

What is the likely result?

A.
The program produces the correct result, with similar performance to the original.

B.
The program produces the correct result, with performance degraded to the equivalent of being
singlethreaded.

C.
The program produces an incorrect result.

D.
The program goes into an infinite loop.

E.
An exception is thrown at runtime.

F.
The program produces the correct result, with better performance than the original.

Explanation:

join() does not proceed until the task’s result has been computed. Here we start to wait
beforedoing the computing. The code will not finish.



Leave a Reply 8

Your email address will not be published. Required fields are marked *


Tim

Tim

The question is incomplete.

Tim

Tim

However, to make the answer as D, the complete question should be something like:

If we change Line X to “return f2.join() + f1.compute()”, what is the likely result?

Erkin

Erkin

If we change Line X to “return f2.join() + f1.compute()”, the answer should be B. Because, Fibonacci(n-1) must wait for Fibonacci(n-2) and Fibonacci(n-2) must wait for Fibonacci(n-3) until n reaches to 1. Although, it would semantically seem execution is parallel, it is not.

test

test

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/RecursiveTask.html

The exact code can be found in the oracle website.

Quote : “However, besides being a dumb way to compute Fibonacci functions (there is a simple fast linear algorithm that you’d use in practice), this is likely to perform poorly because the smallest subtasks are too small to be worthwhile splitting up. Instead, as is the case for nearly all fork/join applications, you’d pick some minimum granularity size (for example 10 here) for which you always sequentially solve rather than subdividing.”

I would say B then based on the last sentence.

An infinite would occur if the

“if(n<=1)
return n;"

is absent or if this.join() is present anywhere.

Google

Google

Wonderful story, reckoned we could combine a number of unrelated information, nonetheless actually worth taking a look, whoa did 1 study about Mid East has got more problerms at the same time.