Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 28 confirmation #88

Open
VishGov opened this issue Nov 3, 2019 · 2 comments
Open

Chapter 28 confirmation #88

VishGov opened this issue Nov 3, 2019 · 2 comments

Comments

@VishGov
Copy link

VishGov commented Nov 3, 2019

Hi Esteban,

In chapter 28 for the RecursiveTask example code,

FindMinimumAction firstSubtask =
new FindMinimumAction(data, start, mid);
FindMinimumAction secondSubtask =
new FindMinimumAction(data, mid, end);
// queue the first task
firstSubtask.fork();
// Return the miminum of all subtasks
return Math.min(firstSubtask.compute(),
secondSubtask.join());

Could you elaborate why we are forking AND also computing the first task, and then joining with the second?

From the notes, I thought that its generally the first is forked, the second computed and we wait on the result of the forked first task( which is usually "stolen" by another worker thread)

Or does it not really matter?

Thanks and Regards,
Vishnu

eh3rrera added a commit that referenced this issue Nov 3, 2019
@eh3rrera
Copy link
Owner

eh3rrera commented Nov 3, 2019

Hi VishGov. You're right, the recommended way is to join the first task, I've changed the example. The text and the other examples also reflect this. However, in practice, most of the time it doesn't matter. Parallelism is a bit tricky to get it right, it depends on the complexity of the task and the number of cores of the computer executing the code.

Some links:
https://stackoverflow.com/questions/30242516/in-javas-forkjointask-does-the-order-of-fork-join-matter
https://stackoverflow.com/questions/50757332/forkjointask-order-of-join-ing

Thanks!

@VishGov
Copy link
Author

VishGov commented Nov 4, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants