we know CPU can reord instructions. and OS simulate multithreading by dispatch.
following cpu machine instructions:
ins0
ins1
ins2
thread0 partition these three ins into 2 parts. part0 execute ins0, part1 execute ins1 and ins2. before part0 start, part2 complete. and then thread1 is triggered.
my question is:should part0 be completed before thread1 start? or thread1 start while thread0 complete ins1 and ins2 without completing ins0?
The short answer is that, with very few exceptions, when a CPU switches from one thread to another, it picks an instruction boundary and completes every instruction prior to that boundary and doesn’t start any after that boundary. When it resumes, it starts from the first instruction after that boundary.