I have worked on multithreading (in Qt) but i lack an in-depth knowledge. I think that the run-time never duplicates an execution code. A function will remain in precisely one memory location which all callers or object will use to invoke it. In multithreading i read that each thread gets its own stack, Instruction Pointers and so on. Let's say we have a global function which translates to assembly algorithm like this:
1 2 3 4 5 6 7 8 9 10 11 12
instruction 1 : move value 4 into accumulator
instruction 2 : add 5 to content of accumulator
instruction 3 : subtract 1 from content of accumulator
//some more stuff and function returns
now maybe the instruction pointer of thread 1 points to instruction 3 while thread 2 gets the slice and executes instruction 1. After this thread 1 executes instruction 3. Won't the accumulator data be corrupted for it? If so then why do functions using only non-static local variables do not require locking in multithreaded environment?