开发者

threads and high level languages

开发者 https://www.devze.com 2022-12-15 13:25 出处:网络
can someone tell me 开发者_如何学运维why if i use threads it\'s better to use an low level languages like c++

can someone tell me 开发者_如何学运维why if i use threads it's better to use an low level languages like c++ and not c# and JAVA? someone asked me that in an interview and i did'nt know the answer


It's news to me. Higher level languages provide easy to use abstractions over thread management, for example.

I expect the interviewer's point would make sense in context. It's dependent on the problem in hand - the level of timing control you need if you're writing a computer game or software for an engine management system may be greater than if you are writing a conference room booking system.

You trade off the low-level control and the associated learning curve and risk you get with lower-level languages for ease of use, safety and productivity of higher-level languages.


I don't think this is necessarily true. In Java (I can't comment on C#) a thread maps directly to a native thread. From here:

The Java HotSpot™ virtual machine currently associates each Java thread with a unique native thread. The relationship between the Java thread and the native thread is stable and persists for the lifetime of the Java thread.

plus you have the additional high level constructs such as the Executor framework.

Going forwards, functional languages (such as F# and Scala) encourage immutability, which contribute to a safer threaded environment.

There may well be scenarios where a low-level language offers more control (as for most requirements), but I suspect those will be fairly specialised situations. You have to balance that against the safety/productivity that the higher-level languages offer.

EDIT : From your comments supplementing the question, this may relate to running a garbage collector and consequent garbage-collection pauses and the impact on providing real-time performance and predictability. Threading in C/C++ may well offer some benefits in this area since a garbage collection cycle is not going to kick off during some critical time-dependent code. For this reason (amongst others) Java can't be considered as a real-time platform.


like most answers : it depends. languages with built in threading facilities like C# and Java will do some or most of the work needed for thread usage and synchronization for you.

with C++ you have do it yourself but you can employ better optimization techniques for your specific OS and platform


Will you use threads or not - depends solely on application, not on language. And language is a function of design. C++ provides more control, c# provides more abstraction, Java provides simplification, but in the end they all work the same way.

0

精彩评论

暂无评论...
验证码 换一张
取 消