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

19/20 Sem2 Q5 #405

Open
darylyeejh opened this issue Apr 27, 2021 · 10 comments
Open

19/20 Sem2 Q5 #405

darylyeejh opened this issue Apr 27, 2021 · 10 comments
Labels
🧠 Finals Q&A Questions related to Finals

Comments

@darylyeejh
Copy link

I think 1 is guaranteed to be printed out because of join(), but does join() also guarantee that 1 will be printed out before the other numbers are printed out? If yes/ no then why

Picture1

@darylyeejh darylyeejh added the 🧠 Finals Q&A Questions related to Finals label Apr 27, 2021
@ryo-wijaya
Copy link

ryo-wijaya commented Apr 27, 2021

Yeah I think so. If I'm not wrong join() is blocking. So the answers for this question has to start with 1.

@JoelToh404
Copy link

yes all the answers have to start with a 1

@bandytan
Copy link

.join() waits for 1 to be completed and prints 1 out first. Since there is no .join() on 2,3,4, they might not be completed and printed out. If they are printed, 4 has to be after 2 or 3. The order of 2 and 3 does not matter.

@brendancjz
Copy link

So what should the answer for this qn be? (a), (e), (i), (j), (n)?

@Buwoo
Copy link

Buwoo commented Apr 28, 2021

Fyi this problem has been discussed on #333

@rljw
Copy link

rljw commented Apr 28, 2021

So what should the answer for this qn be? (a), (e), (i), (j), (n)?

I think the answer for this should be (a), (e) and (n). Options (i) and (j) are not possible because.thenRun(() -> printAsync(4))comes after the .allOf() function, meaning that 2 and 3 both have to be printed before 4 would be printed. Hope that helps!

@danieltwh
Copy link

So what should the answer for this qn be? (a), (e), (i), (j), (n)?

I think the answer for this should be (a), (e) and (n). Options (i) and (j) are not possible because.thenRun(() -> printAsync(4))comes after the .allOf() function, meaning that 2 and 3 both have to be printed before 4 would be printed. Hope that helps!

Yeap agreed. In this case, 1 is definitely printed. However, 2 or 3 or both could be printed after 1. If 4 is printed, then both 2 and 3 (in any order) has to be printed. Hence, the output should be (a), (e) and (n)

@chelleadel
Copy link

Hi! I agree with the others that the method .join() waits for the internal process to complete its execution before allowing any other programs to continue on. Therefore, it is a guarantee that 1 will come out first and the answer is A E I J N.

@clementyee303
Copy link

clementyee303 commented Apr 28, 2021

Hi! I agree with the others that the method .join() waits for the internal process to complete its execution before allowing any other programs to continue on. Therefore, it is a guarantee that 1 will come out first and the answer is A E I J N.

I and J are not possible. For 4 to complete, both 2 and 3 has to complete first.

@ErMingYong
Copy link

since 1 has a .join(), 1 will definetly be exeuted and completed first -> 1 will surely bet he first output
however, 2 and 3 are executed without a join and it runs for undetermined amount of time, hence they could either both be completed, or either being completed or none at all.
Lastly, 4 has a .thenRun(), hence can only be executed when both 2 and 3 are completed.
Therefore, the output has to have 1 being the first, 2 and 3 can be in random order or even none and lastly, should there be a 4, then both 2 and 3 have to be present and placed before 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧠 Finals Q&A Questions related to Finals
Projects
None yet
Development

No branches or pull requests