Multi Tasking

Windows can keep track of multiple programs at once. How can you emulate something like this in C++? For example, emulating two particles at the same time instead of one and then the other?
Last edited on
There are two ways of doing this. First is the way you are probably thinking of, which is multithreading. This exploits the fact that you normally have more than one CPU core, so they can process in parallel. Note that multithreading is one of the most complicated topics in C++, due to weird errors from doing things like writing somewhere at the same time in multiple threads.

The second way, which is (I think) generally the way that Windows does it, is simply task switching. As in, emulating one particle and then the other, but alternating based on whichever one requires more at the time. There would be some multithreading going on to, but how would it run more than 8 programs if your CPU only has 4 cores?

Generally, unless you REALLY need the speed boost from multithreading (and you are certain you can write multithreaded code that does actually give a speed boost) its fine just to task switch.
Last edited on
I was asking about number two, Multi-threading sounds like a terrible practice don't you think? (unless you are running a custom OS built for something super powerful)
I was asking about number two, Multi-threading sounds like a terrible practice don't you think? (unless you are running a custom OS built for something super powerful)
No. You'll probably find that even your phone has multiple cores, it's pretty much ubiqutous.

Also, you need to remember that the CPU is rarely fully utilised. Most of the time is spent doing I/O, where the CPU is mostly idle, so multithreading can very well be used effectively in a single core environment.
Last edited on
Bah, you win. It sounds like it's pretty complicated to do though and like NT3 said,
most complicated topics in C++, due to weird errors from doing things like writing somewhere at the same time in multiple threads.


This doesn't sound very good to me unless I know what I'm doing, which I never do.
Topic archived. No new replies allowed.