I am new to multithreading but in every tutorial that I have found it says to use the join method so that you wait for each thread to finish before doing the next one. What is the point of multithreading if each thread executes one at a time?
CodePudding user response:
The idea is that you can start 4 threads, and then join 4 threads. This works well when each thread can do a quarter of the work.
If your problem is sequential in nature, you're indeed right that threads do not help. This is a well-known restriction; it's called Amdahl's Law and was observed already back in 1967.
CodePudding user response:
Lets say you have 1.000.000 datasets you need to access and modifiy. If you have a single threaded application, you need to wait to finish 1.000.000 datasets.
With multithreading you can split the work and each thread executes simultaneously. If you have 1.000.000 datasets and 4 threads, in the very best case you only need to wait as long as if you had 250.000 datasets.
If you have no dependencies between executions and your workload is heavy, you should consider using multithreading.
