Design – what makes Erlang suitable for soft real-time applications?

Some background

I am working on building a programming language for digital media programming. It should support non shared messaging and soft real-time concurrency (i.e. calculate audio / video as much as possible without losing samples or frames, and have constant throughput)

It turns out that these two features are surprisingly difficult to combine, mainly because of a specific constraint: real-time code should not dynamically allocate memory

My language should be easy to implement such things:

A thread calculates audio samples based on parameters These can be, for example, the values of different controls of the synthesizer The thread "runs in real time" > A thread receives input from a user or another computer to change these values This can be a GUI thread, for example, responding to a user turning a knob with a mouse

I want the new value set by the user to be sent to the synthesizer engine through the queue Now, if I just want to send floating point numbers and other atomic values, the problem won't be very interesting In fact, I hope that any type of data can flow from one thread to another, or even a complex object or data structure, which is feasible for any configuration of threads and priorities Without dynamic memory allocation, it becomes very difficult in real time without imposing any arbitrary restrictions on programmers

Erlang is often advertised as suitable for real-time systems My understanding is that Erlang never prohibits memory allocation If I did the same, the introduction of non deterministic time costs into the code that executes these assignments would eliminate many problems

problem

So what makes Erlang so suitable? Does it implement special techniques to avoid the problem caused by memory allocation, or ignore it completely? Is another real-time method needed?

An example is given to illustrate this problem

Suppose we write a synthesizer in Erlang, which must generate 64 samples every 50 milliseconds, otherwise cracks and sounds will appear in the sound We also assume that when I move some sliders on the string, a small object (assuming it is a list or tuple containing parameter names and new values) must be sent from the GUI process to the audio process, where a copy is created This will require dynamic memory allocation How does Erlang help me ensure that this allocation does not delay my audio calculations?

Solution

Real time code can dynamically allocate memory, just need to be more careful

In the case of real-time hard real-time, dynamic memory processing will become another factor, which must be considered when determining whether the system can perform tasks within the allocated time This is the worst case scenario

In soft real time, it is usually enough to check dynamic memory. Processing will not take much time and lead to long pause time Soft is the average

Erlang system is quite good for soft real-time applications. Dynamic memory processing is quite efficient and usually does not cause any obvious pause Although it may introduce some uncertainty itself, it should not have any problem in itself I mean, if time is important to you, you should be the timing of the application, such as the arrival of audio samples on time

This is a completely different problem if Erlang is the correct language for your application One thing without real optimization is numerical calculation Erlang can certainly do this, but the speed of low-level language has not For applications that already use Erlang, they are usually not important But there is another wings 3D, an open source subdivision modeler inspired by nindo and Mirai of izdor, which is written in Erlang So there is no hope

These are the designs collected by programming house for you – what makes Erlang suitable for soft real-time applications? I hope this article can help you solve the design - what makes Erlang suitable for soft real-time applications? Program development problems encountered.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>