为什么 RTOS 只用 c 语言编码?

发布于 2024-08-14 18:25:10 字数 64 浏览 4 评论 0原文

RTOS有必要一直用C语言编写吗?为什么不能用 java 或其他技术进行编码..?是因为java中没有指针概念吗?

Is it necessary to code RTOS in C language always? Why can't that be coded in java or some other technology..?? Is that because of the absence of pointer concept in java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

半衬遮猫 2024-08-21 18:25:10

垃圾收集是阻碍 Java 实时化的重要原因。 JIT 是另一个问题,但它是可以克服的。

但总的来说,C 是有效的可移植汇编,可提供非常可预测的运行时性能,这对于可靠的实时执行至关重要。

Garbage collection is the big reason against Java being Real Time. JIT is another, but it could be overcome.

In general though, C being effectively portable assembly gives very predicable run-time performance, and that's essential for reliable real-time execution.

江湖正好 2024-08-21 18:25:10

实时系统也可以用其他语言进行编程。例如,Java 有一个 Java RTS 系统

与其他答案相反,实时垃圾收集有合理的工作量。但是,这些不会捆绑在您的典型发行版中。

令人担忧的是,其他语言通常具有难以实现确定性和可靠性的功能,例如传统的垃圾收集、JIT、运行时优化等。

Real time systems can be programmed in other languages too. Java has a Java RTS System for example.

Contrary to other answers, there is reasonable amount of work on real-time garbage collections. However, these don't get bundled in your typical distributions.

The concern is that other languages usually have features that make determinism and reliability hard to achieve, e.g traditional garbage collection, JIT, run-time optimizations, etc.

南街女流氓 2024-08-21 18:25:10

最初,RTOS 不仅仅用 C 语言编码。它们还可以用其他语言编码。然而,用于 RTOS 的语言需要提供确定性行为。这意味着特定操作的延迟必须始终低于特定的时间量。这排除了例如垃圾收集,在大多数实现中,垃圾收集将在不确定的时间内停止所有线程的执行。

At first RTOS aren't just coded in C. They can also be coded in other languages. However the language used for an RTOS needs to offer deterministic behaviour. This means that the latency for a specific action must always be under a specific amount of time. This rules out for example garbage collection, which in most implementations will stop the execution of all threads for an undetermined time.

把回忆走一遍 2024-08-21 18:25:10

因为 RTOS 开发人员很可能对 C++ 不够了解。

嵌入式系统中的 C++:神话与现实

有些人认为 C++ 有开销
以及以某种方式呈现它的成本
不适合嵌入式系统
编程,它缺乏控制
以及 C 的简洁性,或者说,虽然它
可能适合某些利基市场
应用程序,它永远不会取代C
作为嵌入式的首选语言
系统。

这些看法都是错误的。在哪里
编译器和其他工具是
足够了,C++ 总是优于
C 作为实现语言
嵌入式系统。在做的同时
C 所做的一切,它提供的一切
更多的表达机会,
封装、重复使用,甚至
允许改进尺寸和速度
这在 C 语言中是不切实际的。

<强>>那么,为什么会有这些认知呢?
坚持?主要原因是当
人们形成自己的意见,他们知道
关于 C 的内容远多于关于 C++ 的内容。
他们读过一些书,写过一些书
一些代码,并且能够使用
具有 C++ 的功能,但缺少
了解下面发生的事情
引擎盖,熟悉的感觉
一个可视化拆卸,同时
输入源代码,甚至同时输入
制定设计。

在嵌入式设计中使用 C++ 替代 C 的指南

嵌入式软件应用程序最常使用 C 语言编写。多年来,C++ 已
被视为自然的继承者并得到了更多的接受,但
它的使用速度比预期慢得多。

造成这种情况的原因有很多。首先,嵌入式开发人员相当
保守,更喜欢使用经过验证的解决方案而不是新颖的解决方案“”
没有坏,不要修理它”。

还有经验教训。许多开发人员尝试使用 C++
嵌入式应用程序失败。此类失败有时可能归因于
开发工具的缺点,但最常见的是使用不当
语言“像对待台式计算机一样对待嵌入式系统”就是罪魁祸首。

C 的局限性
尽管 C 语言被广泛使用,但它也有局限性,因为它不是为嵌入式设计的
应用程序或现在司空见惯的规模的项目。主要限制包括:

1) C 非常强大和灵活,因此可能很危险。(它的级别较低
功能 - 这对嵌入式很有用,但也代表了许多陷阱
不小心。)

2)程序员需要非常有条理和有纪律

3) 程序员需要了解程序在低层和高层(大型
因此项目很难维护)

4) 程序员需要应用程序的专业知识

但是,C++ 具有强大的面向对象功能,可以显着帮助
解决 C 的局限性:

1) 它将非专家的高度专业知识领域封装并隐藏到“对象”中; (一个
测试用例将在本部分第 2 部分稍后展示专业知识的封装
系列)。

2) 非专家也可以直观地使用对象来实现概念设计
高级别

Because RTOS developers, most likely, don't know C++ well enough.

C++ in Embedded Systems: Myth and Reality

Some perceive that C++ has overheads
and costs that render it somehow
unsuited to embedded systems
programming, that it lacks the control
and brevity of C, or that, while it
may be suited to some niche
applications, it will never displace C
as the language of choice for embedded
systems.

These perceptions are wrong. Where
compilers and other tools are
adequate, C++ is always preferable to
C as an implementation language for
embedded systems. While doing
everything that C does, it offers
greater opportunities for expression,
encapsulation, re-use, and it even
allows size and speed improvements
that are impractical in C.

> Why, then, do these perceptions
persist? The main reason is that when
people form their opinions, they know
a lot more about C than about C++.
They have read some books, written
some code, and are competent at using
the features of C++, but they lack the
knowledge of what is happening under
the hood, the familiarity that allows
one to visualize the disassembly while
typing source or even while
formulating a design.

Guidelines for using C++ as an alternative to C in embedded designs

Embedded software applications are most commonly written in C. For many years, C++ has
been seen as the natural successor and has found greater acceptance, but the increase in
its usage has been much slower than anticipated.

There are a number of reasons for this. Firstly, embedded developers are quite
conservative and prefer to use solutions that are proven rather than novel " "if it
ain't broke, don't fix it".

There is also the lesson of experience. Many developers have attempted to use C++ for
embedded applications and failed. Such failures may sometimes be attributed to
shortcomings in development tools, but most often it is the inappropriate use of the
language " treating an embedded system like a desktop computer " that is to blame.

Limitations of C
Although C is widely used, it has limitations, as it was not designed for embedded
applications or for projects of a scale that is now commonplace. Key limitations include:

1) C is extremely powerful and flexible and can therefore be dangerous.(It has low level
capabilities - which are useful for embedded " but also represent many pitfalls for the
unwary.)

2) Programmers need to be very methodical and disciplined

3) Programmers need to understand how the program behaves at low and high levels (large
projects are thus hard to maintain)

4) Programmers need an expert knowledge of the application

However, C++ has powerful object oriented capabilities which can help significantly with
addressing the limitations of C:

1) it encapsulates and hides areas of high expertise from non-experts into "objects;" (A
test case will demonstrate the encapsulation of expertise later in Part 2 in this
series).

2) Objects can be used intuitively by non-experts to implement conceptual designs at a
high-level

懒的傷心 2024-08-21 18:25:10
  • 高度优化的 C 编译器适用于 RTOS-es 通常运行的所有硬件。
  • 您可以相对轻松地
    包括非常低级别的优化
    在c代码中。
  • C 代码的可用性对于很多
    有用的低级系统工具
    因此可以很容易地合并。
  • Availability of highly optimized c-compilers for all hardware that RTOS-es typically run on.
  • The relative ease with which you can
    include very low level optimizations
    in c-code.
  • Availability of c-code for a lot of
    useful low-level system tools which
    hence can easily be incorporated.
白首有我共你 2024-08-21 18:25:10

根据定义,RTOS 必须支持确定性调度和执行。一般来说,低中断延迟和直接硬件访问也是一个理想的因素。 Java 中使用的垃圾收集、JIT 编译和字节码执行等技术使这些目标难以实现。

Java 可用于实时系统,但通常它运行在 RTOS 上,而不是在其实现中使用。

尽管如此,认为 RTOS 总是用 C 实现的说法同样是不正确的。任何系统级语言都适合,包括汇编语言。在大多数情况下,至少内核的某些部分将在汇编程序中。 C++ 将是一种合适的语言(很明显,因为它本质上是 C 的超集),许多商业 RTOS 无论如何都有 C++ 包装器;我习惯性地为 RTOS 开发 C++ 抽象层以支持可移植性。

通常使用 C 的另一个原因是,C(通常是 C/C++)编译器通常是第一个且通常是唯一可用于新体系结构的语言(汇编程序除外)(如今通常以 GNU 编译器实现的形式) )。因此,如果您希望能够将 RTOS 移植到最广泛的平台,那么使用最普遍的语言是有意义的。

By definition an RTOS must support deterministic scheduling and execution. Generally low interrupt latency, and direct hardware access are also a desirable factor. Technologies used in Java such as garbage collection, JIT compilation, and bytecode execution make these goals hard to achieve.

Java may be used in real-time systems, but typically it runs on an RTOS rather than being used in its implementation.

All that said, it would equally be untrue to suggest that RTOS are always implemented in C. Any systems level language would be suitable including assembler. In most cases at least some part of the kernel would be in assembler in any case. C++ would be a suitable language (rather obviously since it is essentially a C superset), many commercial RTOSs have C++ wrappers in any case; I habitually develop C++ abstraction layers for RTOS to support portability.

The other reason C is typically used is because a C (often a C/C++) compiler is generally the first and often the only language (other than assembler) available for a new architecture (frequently these days in the form of a GNU compiler implementation). So if you want to be able to port your RTOS to the widest number of platforms, it makes sense to use the most ubiquitous language.

不念旧人 2024-08-21 18:25:10

不是“必要的”,但更实用

作为一种可以使用 Java 的语言,并且实际发生了各种奇怪的情况。

但一些边缘案例和演示实际上更像是“证明规则的例外”。

一般来说,Java 是一个大型复杂系统,旨在用于业务逻辑而不是操作系统内核。

如果我们还没有 C,Java 可能会朝不同的方向或多个方向发展。

但我们确实有 C,它对于操作系统内核来说几乎是完美的,但对于业务逻辑来说却是一个相当大的挑战。

对于内核来说,Java 和 C 一样好,这与应用程序方面 C 和 Java 一样好,都是现实的。经验,减去一些边缘例子,压倒性地证明了每种语言的优点。

Not "necessary", but a lot more practical

As a language Java could be used, and there are various wacky cases of it actually happening.

But a few fringe cases and demonstrations are really more "the exception(s) that prove the rule".

In general, Java is a big elaborate system intended for business logic and not OS kernels.

If we did not already have C, Java might have developed in a different direction, or in multiple directions.

But we do have C, which is nearly perfect for an OS kernel and quite a challenge for business logic.

Arguments that Java is just as good as C for a kernel are about as realistic as arguments that C is just as good as Java for applications. Experience, minus a few fringe examples, proves overwhelmingly what each language is good for.

凉城 2024-08-21 18:25:10

我认为java为此目的最大的问题是自动垃圾收集。这是关于用 Java 创建实时系统的链接

I think the biggest problem with java for this purpose is the automatic garbage collection. Here's a link on creating realtime systems in java.

叶落知秋 2024-08-21 18:25:10

因为基于 C 的 RTOS 众所周知并且已经使用了几十年。在许多特定情况下,它们的行为是可预测的,您可以找到许多使用这些系统进行开发的专家。

据我所知,基于 Java 的 RTOS 还没有达到能够让制作安全关键型实时应用程序的公司采用它的水平。

从技术上讲,基于 Java 的 RTOS 是没有争议的,但该主题的研究、工程和产品尚不成熟。

Because C-based RTOS are well known and have been used for many decades. Their behaviour is predictable for many specific situations and you can find many experts for developing with these systems.

I know no Java-based RTOS having reached a level such that a company making safety critical realtime applications would adopt it.

Technically, there is no argument against a Java-based RTOS, but research, engineering and products on the subject is not yet mature.

迷途知返 2024-08-21 18:25:10

是否需要一直用C语言编写RTOS?

不。您还可以使用汇编器、Ada 和其他一些语言来编写 RTOS。

为什么不能用 java 或其他技术进行编码..?这是因为java中没有指针概念吗?

不可以。代码执行时间不可预测。

Is it necessary to code RTOS in C language always?

No. You can code RTOS also in assembler, Ada and few other.

Why can't that be coded in java or some other technology..?? Is that because of the absence of pointer concept in java?

No. Unpredictable time of code execution.

长安忆 2024-08-21 18:25:10

Java中有Real Time,但它需要操作系统的支持。
请参阅: http://java.sun.com/javase/technologies/realtime/索引.jsp

There's Real Time in Java, but it requires support from the OS.
See: http://java.sun.com/javase/technologies/realtime/index.jsp

一世旳自豪 2024-08-21 18:25:10

C 是为编写操作系统而设计的,因此常见的措辞是“便携式汇编程序”,因此可以预期它用于此目的。

如果您想要实时 Java,Sun 有一个商业产品。

C was designed for writing operating systems, hence the common wording "portable assembler", so it is to be expected that it is used for that purpose.

If you want to have real time Java, Sun has a commercial offering.

韶华倾负 2024-08-21 18:25:10

如果有的话,那是因为指针。在 Java 中,除了基本数据类型之外的所有数据都在堆上分配,并且任何不同于 int 的变量都是指针。这不是编写操作系统的好方法,因为它对大多数操作强加了一层间接性,而在操作系统编写中,这一层可能会杀了你。

操作系统内核是您需要优化和高性能的地方,因为您不知道将在其上运行什么。对于实时操作系统尤其如此,其中半毫秒的延迟可能至关重要。这需要与 CPU 和其他硬件真正融洽,并且能够编写高度微优化的代码,以高度可预测性执行特定的操作。

因此,C 是构建 RTOS 内核的非常好的工具,而 Java 则不是。这并不意味着您不能使用 Java 来做到这一点,但它会更难,而且可能不会那么成功。

我很好奇你为什么问这个问题。如果您使用的是 RTOS,那么它是用什么编写的并不重要。如果您想破解一个 RTOS,那么它是用什么编写的确实很重要,但是操作系统的概念和实现本身就足够困难了学习一门新语言是微不足道的。 (此外,如果您研究操作系统设计和实现,您几乎肯定会发现您使用的资源将使用 C 作为教学语言。)

If anything, it's because of pointers. In Java, everything except fundamental data types is allocated on the heap, and any variable that isn't something like int is a pointer. That's not a good way to write an operating system, because it imposes one layer of indirection over most operations, and in OS writing that layer can kill you.

The OS kernel is a place where you want optimization and high performance, since you don't know what will run on it. This is particularly true of real-time OSs, in which a half-millisecond delay can be critical. This requires getting really chummy with the CPU and other hardware, and the ability to write highly microoptimized code that will execute specific things with great predictability.

For this reason, C is a very good tool to build a RTOS kernel with, and Java isn't. That doesn't mean you couldn't do it with Java, but it would be harder and probably not as successful.

I am curious as to why you ask the question. If you're using a RTOS, it doesn't really matter what it was written in. If you want to hack one, it does matter what it was written in, but the concepts and implementation of the OS are sufficiently hard in themselves that learning a new language is trivial to learn. (Moreover, if you study OS design and implementation, you're almost certain to find that the resources you use will use C as a teaching language.)

携余温的黄昏 2024-08-21 18:25:10

RTOS 并不总是用 C 编写。通常是这样,但在 ThreadX 中我相信它们使用汇编。

An RTOS isn't always written in C. Usually it is so, but in ThreadX I believe they use assembly.

别闹i 2024-08-21 18:25:10

是否需要一直用C语言编写RTOS?

不会。例如,有些 RTOS 是用 Lisp 或 Smalltalk 编写的。

为什么不能用 java 或其他技术进行编码..??

是什么让你认为不能?

这是因为java中没有指针概念吗?

不,这是因为有一个神话,即操作系统只能用 C 语言编写。这个神话可以被证明是错误的,但仍然拒绝消亡。

这个神话如此普遍,以至于那些想要编写新操作系统的人都不敢尝试 C 以外的任何东西。

Is it necessary to code RTOS in C language always?

No. There are RTOS written in Lisp or Smalltalk, for example.

Why can't that be coded in java or some other technology..??

What makes you think it can't?

Is that because of the absence of pointer concept in java?

No, it's because there is a myth that Operating Systems can only be written in C. A myth that can be trivially proven false, yet still refuses to die.

This myth is so pervasive, that people who want to write a new OS, are simply too afraid to try anything other than C.

耳根太软 2024-08-21 18:25:10

像 Java 这样的垃圾收集语言非常适合实时编程。其原因应该是显而易见的。

A garbage-collected language like Java is highly unsuited for real-time programming. The reasons for this should be obvious.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文