public int getAllCandidatesUsing8(int num) {
final int[] cnt = {0};
int pow = (int) Math.pow(2, num);
IntStream.range(0, pow).parallel()
.forEach(i -> {
//computing codes
cnt[0]++;
});
return cnt[0];
}
Above code is a small part of my codes to show the problem.
I ran the method with input of number 8 but got wrong answer like 63, 61, 62 not always 64 which is the right answer.
If I'm not using parallel, it works correctly. (btw, I use parallel because the input is quite large: num might be hundreds)
Why?