Best practice regarding number of threads in GUI applications

后端 未结 9 1308
谎友^
谎友^ 2021-01-19 16:43

In the past I\'ve worked with a number of programmers who have worked exclusively writing GUI applications.

And I\'ve been given the impression that they have almost

9条回答
  •  礼貌的吻别
    2021-01-19 17:41

    As the prior comments said, GUI Frameworks (at least on Windows) are single threaded, thus the single thread. Another recommendation (that is difficult to code in practice) is to limit the number of the threads to the number of available cores on the machine. Your CPU can only do one operation at a time with one core. If there are two threads, a context switch has to happen at some point. If you've got too many threads, the computer can sometimes spend more time swapping between threads than letting threads work.

    As Moore's Law changes with more cores, this will change and hopefully programming frameworks will evolve to help us use threads more effectively, depending on the number of cores available to the program, such as the TPL.

提交回复
热议问题