I really don't see the logic of the first exercise, with Thread.yeld. If Random is greater than 500, you pause the tread and give the time of the CPU to another thread, it executes and then it comes back and executes this thread?! I think I unterstand the method, Thread.yeld, but I the example, for me, doesn't make sense. The second exercise is straight forward. If you make some examples and play with the yeld method you see the results.
I do not get it. Why is "correct place" specifically after first statement? Why it cannot be before first statement? That would seem more logical to me
The term "time slice is surrendered" typically refers to a situation where a process in a multitasking operating system voluntarily relinquishes its share of the CPU's processing time, allowing other processes to use it instead.
In a multitasking operating system, the CPU is divided into time slices, or small units of time, which are allocated to each running process in turn. When a process has completed its task or is waiting for input/output operations to complete, it may voluntarily surrender its time slice so that another process can use the CPU. This helps to ensure that all processes get a fair share of the CPU's processing time and that the system remains responsive.
The act of surrendering a time slice may be initiated by the process itself, or it may be triggered by the operating system, which may interrupt the process and schedule another process to run in its place.
GO TO FULL VERSION