Issue
English is not my native language so I apologize for any inappropriate use of it.
I am learning about multi-threaded programs, so (on my laptop with Windows8 HyperV) I made emulated Ubuntu12.04.4 with one core processor (in my laptop I have two, virtually four). (Processor: Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz || RAM: 6,00 GB || System: Windows 8 64-bit)
After few hours of searching through forums and tutorials, I started testing some codes, but found out, that threads are not executing in correct order.
Code: http://pastebin.com/AX2wTxZ2
Output: https://i.stack.imgur.com/26OeQ.png
Question - can this problem be related to single core or emulation or I have done something incorrect?
Solution
You didn't do anything wrong. The reason you see such result is because... well, because that's how it is. Since both threads run parallely then there's a race condition. There's not much you can do about it, because you don't have control over the order of threads (it's up to OS).
Try running the code few times and you should see the opposite result from time to time.
Answered By - freakish Answer Checked By - Candace Johnson (WPSolving Volunteer)