I have confusion with this particular question on Marcus Green Exam.
Which of the statements are true? Select two.
1. The idea of threading is same as multitasking 2. No two threads can access the same variables 3. using synchronization within a thread may cause performance penalties. 4. the use of threads may make the exact path of execution unpredictable.
4. the use of threads may make the exact path of execution unpredictable.
threads can make the path of execution unpredictable? how come? an execution is a top-down approach, meaning from line 1 to line 2 to line 3 and so forth. it can be interrupted but execution goes to the next line. please help.
Doyle, I think the point is that execution may go from line 4 in thread A to line 10 in thread B. Within a single thread the path of execution is still predictable, but the order of execution across threads is unpredictable in the sense that you don't get any guarantees about it.
This unpredictability does imply that if you don't carefully control the interaction between threads, the behaviour of your entire application becomes unpredictable. This, of course, is the whole issue of thread safety.