I have to solve this exercise but I don't really know how to start!
I mean, I think that the solution for Part a could be that if when thread s is running and unknown() returns 500, then the thread t will be not able to continue, and then after 499 rounds also the thread s will be terminated and so this could be an execution where the program ends. But what happen if unknown() after returning 500 the next round return 499? the thread t could start again?
I really don't understand how to solve it!
Really appreciate if someone can explain me! The course is online so I don't know my course mates and I don't know who to ask for help.
CodePudding user response:
Thread s execution is controlled only by the value of n1. It will terminate no matter what the return value of unknown is, assuming that unknown returns a numeric value.
Thread t execution is controlled only by the value of n2. The variable n2 is impacted in an unknown manner during the execution of thread s, however thread s will eventually terminate. Once thread s terminates then n2 is only impacted by thread t and its value will eventually exceed thread 2's terminating value of 500.
One of the keys to this solution is the fact that computer integer values as represented by the int type do not have an infinite range. Incrementing such an int variable will eventually result in a value that exceeds 500.