Challenges / Possible Issues of Multithreading
It is a challenge to identify:
- What code sections in a program could be divided into tasks that could run concurrently (Identifying tasks.)
- What code sections in a program could be divided into tasks that are roughly the same number of instructions so as not to waste CPU time when one thread runs for much more time than others (Balance.)
- What code sections in a program could be divided into independent tasks to be run by threads (Data splitting.)
- How to synchronize the execution of the threads. If the execution of thread B depends on the results of the execution of thread A, then running B before running A will cause some error in B’s results or corrupt data (Data dependency.)
- Whether the program runs correctly since timing and order of the execution of multiple threads can be unpredictable (Testing and debugging.)