Multi-threading

to use multi threading in one's programme, is it necessary that the target computer's processor should have at least two threads and why?

Aceix.
You can still multi-thread on a computer with only one core, but it's slower because to simulate multi-threading, the core swaps between threads, and swapping has quite a bit overhead.

I'm not an expert on multi-threading, but I'm pretty sure that's the gist of it.
I'm not an expert on multi-threading, but I'm pretty sure that's the gist of it.


You are correct.

Just to elaborate:

Any OS capable of multitasking (ie: every OS made in the past 25+ years) has a scheduler, where it takes whatever CPU power the system has available and divvies it out to all running threads.

Your computer right now probably has several dozens if not hundreds of threads running from things like background processes, your browser, and any other programs you have running. The scheduler is keeping an eye on all of that, seeing who needs CPU time and when, and assigning CPU time to that thread.


As mentioned, it does incur some overhead, but it's not really an issue. The scheduler is switching threads constantly... and you'll see this overhead whether you have multiple threads in your program or not.

The real slowdown in multithreaded programs usually comes from data synchronization.
Still, while your hard drive may be busy reading data (operation requested from thread 1), your CPU could do more work on thread 2, or thread 3 may be waiting for socket connections.
Topic archived. No new replies allowed.