Microsoft Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
Correct. If there is a blocking operation like blocking I/O as said by Eugene, the processor can execute instruction from the other thread.
I think "process is pretty responsive" means it is not stuck in I/O operations or any such operations...
i think in this case there won't be much of a difference whether we use multithreading or single threading...
for. eg.. if we are downloading a page on a browser and all blocks have html data..why would we use multithreading? multithreading in that case would only increase the time involved in context switching..Multithreading helps only when some blocks are heavier than the other and take more time to respond(due to I/O operations or any such operation)
I hope u r getting my point.
Most programs have at least a little I/O. But even if there's no I/O, the hyper-threading argument applies.
You forgot to mention one point.
Sometimes, designing for multiple threads simplifies the code and makes it easier to maintain etc.
Of course, finding bugs due to race conditions becomes trickier, but in general, the code is less brittle than trying to cram asynchronous IO etc in one thread.
Actually Yes..... by using threads you are doing multitasking ... now you are doing all the tasks at the same time span .... multitasking in single core processor takes longer time than serial tasking because of context switching but if the number of threads are less then it will work just fine..
Sure, there could still be benefits. I don't know what you mean by "process itself is pretty responsive", but I would note that having multiple threads allows you to do tasks while one thread is, for example, waiting on disk I/O or network I/O to complete.
- eugene.yarovoi January 19, 2012_
Furthermore, processors employing hyper-threading can execute instructions from multiple threads simultaneously. This may offer a performance advantage because instructions from one thread can run when the instruction stream from another thread is stalled because of data hazards or memory access latency.