No it is impossible, by definition multi-threading adds more work for the processor to do, it now has to control scheduling the different threads.
You use multi-threading to allow you to run 2 threads of execution that have little or nothing to do with each other asynchronously so that you can write the code of each thread without having to worry about what the other thread is doing. Not to speed up the program.
Hmmm, well actually I guess with modern multi-core processors you may be able to get a speed increase. However I have a feeling that by default Windows runs all the threads of a single process on the same processor. But that is a guess I am not sure and I have absolutely no idea what happens on Linux.
No it is impossible, by definition multi-threading adds more work for the processor to do, it now has to control scheduling the different threads.
You use multi-threading to allow you to run 2 threads of execution that have little or nothing to do with each other asynchronously so that you can write the code of each thread without having to worry about what the other thread is doing. Not to speed up the program.
Hmmm, well actually I guess with modern multi-core processors you may be able to get a speed increase. However I have a feeling that by default Windows runs all the threads of a single process on the same processor. But that is a guess I am not sure and I have absolutely no idea what happens on Linux.
How can we do multi threading for running multiple tasks .
How can we do multi threading for running multiple tasks .
Writing thread-safe code takes discipline. You need to decide which variables should be local to each thread and which should be shared in common by all the threads. Then you need to implement your code such that it correctly implements those variable scope decisions. You need to design strategies to protect all the common variables so that simultaneous access from multiple threads doesn't cause problems.
Comment