If a program is having 2 functions with 2 threads, does it mean CPU will run both the functions simultaneously in two threads? Assuming that I have dual core system where each core is having 2 physical threads.
Yes. In this case your CPU will make sure that it always runs your two functions simultaneously in 2 CPU threads.
No. Still it runs in a single thread of your CPU.
Answer is you can't guarantee. Even though you have created multiple threads and your system is having multi cores and multi threads, still the final decision will be taken by O.S. If O.S feels that your two functions doesn't really require 2 separate CPU threads because may be your functions are not so heavy, in that case OS scheduling algorithm will redirect both the threads( functions) to single CPU thread only.
Back To Top