Is there a point to multithreading?

后端 未结 11 873
无人共我
无人共我 2021-01-02 17:22

I don’t want to make this subjective...

If I/O and other input/output-related bottlenecks are not of concern, then do we need to write multithreaded code? Theoreti

11条回答
  •  无人及你
    2021-01-02 17:59

    Most of the answers here make the conclusion multicore => multithreading look inevitable. However, there is another way of utilizing multiple processors - multi-processing. On Linux especially, where, AFAIK, threads are implemented as just processes perhaps with some restrictions, and processes are cheap as opposed to Windows, there are good reasons to avoid multithreading. So, there are software architecture issues here that should not be neglected.

    Of course, if the concurrent lines of execution (either threads or processes) need to operate on the common data, threads have an advantage. But this is also the main reason for headache with threads. Can such program be designed such that the pieces are as much autonomous and independent as possible, so we can use processes? Again, a software architecture issue.

    I'd speculate that multi-threading today is what memory management was in the days of C:

    • it's quite hard to do it right, and quite easy to mess up.
    • thread-safety bugs, same as memory leaks, are nasty and hard to find

    Finally, you may find this article interesting (follow this first link on the page). I admit that I've read only the abstract, though.

提交回复
热议问题