Are single-threaded applications a dead technology

2020-06-03 04:49发布

I just bought a new, sub-US$1,000 laptop, one aimed squarely at the consumer, non-developer market and, looking over the specs, was surprised to find that it came standard with a dual-core processor.

This led me to the question: with multicore machines becoming the norm, is it ever correct to write a single-threaded application anymore?

Excepting trivial applications, which can reasonably be expected to fit entirely within a single core of a single processor of the weakest system on which it will run, will an application which runs in all one thread be seriously degraded by the way modern OSs spread their execution across cores when no guidance is given by the application as to how to optimize such a split?

13条回答
男人必须洒脱
2楼-- · 2020-06-03 04:50

The answer to your question is tricky, because it asks us to speculate on future developement. The simple answer to your question is this:

No, single threads are the basis for multiple threads, you can't have one without the other. Thus, the capacity for single threaded applications will always exist, and they will doubtlessly be written for years to come.

The complex answer is as follows: The reason for computers having dual core processors standard is because its the next step in processor developement. while many applications will not take immediate advantage of the dual core, some will. As such, a company like intel must accomodate, or be squashed by the competition.

Beyond this, there are immediate advantages. Larger addressable memory space. Operating Systems themselves already being optomized for the dual also reaps immediate benefits.

Also: If you have a library that is optimized for the dual core processors all subsequent developement will benefit. An example is searching and sorting algorithms (a nartural choice for "thread split" due to the divisibility of the data) which can be optimized for the dual core, and then be perpectually used with the advantage.

查看更多
▲ chillily
3楼-- · 2020-06-03 04:52

Multiple cores are advertised for the users benefit, not the programmer. A user will be told that having multiple cores means they can run a number of complex applications at the same time, e.g. updating a large spreadsheet in Excel and viewing a Powerpoint presentation etc.

Obviously as a developer you CAN make good use of the extra cores; most video editing packages run far faster on multi-core machines.

If you are writing an application that would seriously benefit from using more cores, then it may well be worth investing the additional development time, as most new machines now have more than one core, but as always, think about the ROI.

查看更多
我只想做你的唯一
4楼-- · 2020-06-03 04:59

Maybe the question should be reformulated to: "is running a program on one only core a dead technology". That would make it a lot more general. If you look at the recent added web workers added to firefox 3.5 and other major browsers, then they do support multiple cores, but using processes and message passing. A much saner approach than threading. In the end it all depends on the problem at hand. Using multiple cores really only makes a difference if the problem at hand is CPU bound.

I would also like to add that your application might not be the only running process on the machine (hint).

查看更多
劫难
5楼-- · 2020-06-03 05:01

... will an application which runs in all one thread be seriously degraded by the way modern OSs spread their execution across cores when no guidance is given by the application as to how to optimize such a split?

No, it will still run just as well as it used run to on a single-core CPU.

查看更多
做自己的国王
6楼-- · 2020-06-03 05:02

Definetely, parallel programming will advance a lot in the future since CPU are not going to become much faster anymore, we simply will have lots of them. Having dual or quad cores is just the beginning, there will be systems with a much higher number of processors in the near future (currently there are CPU with 256 cores, Windows 7 will have support for such processors).

However, I think that parallelism is not suitable for solving any problem and it requires a different style of programming. Using current technology, multi-threading adds a quite high level of complexity to an application. Therefore paradigms such as functional programming as well as libraries/compilers supporting parallelization will become more and more important in the future.

David Callahan had an interesting article in MSDN magazine on the shift in design considerations regarding parallel programming: Paradigm Shift: Design Considerations For Parallel Programming

查看更多
Evening l夕情丶
7楼-- · 2020-06-03 05:03

Since threading always adds extra complexity to applications, I believe that single threaded applications will always have their place.

Not even when single core processors are completely obsolete will single threaded programming be gone.

Dual cores, especially in the consumer market, are great for multitasking. If every app takes every processor core it possibly can we will run into the same problems we had with single core processors.

I say don't go nuts and start mulithreading everything. Keep it in one thread unless there is a good reason not too.

查看更多
登录 后发表回答