Is it possible to create parallel, scalable, reliable programs in C, as in erlang?

theoretical question. After reading the Erlang book written by the Armstrongs, I was wondering: It will take some time to learn Erlang. Not to mention this. It really is fundamentally different in many ways.

So my question is: is it possible to write "like erlang" or with some kind of "erlang like framework", which, given that you do not care about creating functions using side effects, you can create scalable reliable applications, as well as in Erlang ? Perhaps with the same messages loading the paradigm of "mini-processes."

The advantage would be to not throw all your accumulated C / C ++ knowledge over the fence.

Any thoughts on this would be welcome.

+6
c ++ concurrency erlang multicore
source share
6 answers

Yes, perhaps , but ...

Probably the best answer to this question is given by the first rule of Robert Virginia:

"Any sufficiently complex simultaneous program in another language contains a special, informally, erroneous, slow implementation of half Erlang."

A very good rule is to use the right tool for the task . Erlang excels in concurrency and reliability. C / C ++ was not designed with these properties in mind.

If you do not want to discard your knowledge and experience in C / C ++ and your project allows you to use this type of separation, a good approach is to create a mixed solution Write the compatibility, communication, and error handling code in Erlang, then add the C / C ++ parts that will handle the processor and IO information.

+8
source share

You can clearly - the Erlang / OTP system is largely written in C (and Erlang). The question is, "why do you want?"

In the old days, people used their own operating system, but why do you need this?

If you decide to use the operating system, your unwritten software has certain properties - it can be stored on the hard drive, it can talk on the network, it can draw on screens, it can be launched from the command line, it can be called in batch mode, etc. .d. etc.

The Erlang / OTP system is 1.5 M lines of code, which has shown that it provides 99.9999999% uptime in large systems (UK telephone system) - this is an idle time of 31 ms per year.

Using Erlang / OTP, your unwritten software is highly reliable, it can be a hot swap, your unwritten application can go to another resource if a physical computer fails.

Why do you want to rewrite this functionality?

+4
source share

I would break it down into 2 questions

Can you write parallel scalable applications in C ++

Yes. Of course, you can create the low-level designs needed to achieve this.

Do you want to write parallel, scalable, C ++ applications

May be. But if I were going for a very parallel application, I would choose a language that was either designed to fill this void, or simply left myself to it (Erlang, F # and, possibly, C #).

C ++ was not designed to create highly competitive applications. But this, of course, can be changed in this. The cost may be higher than you expect as soon as you accept the memory management factor.

+2
source share

Yes, but you will do extra work.

Regarding side effects, consider how the .net / plinq command approaches. Plinq will not be able to force you to hand, without side effects, but he will assume that you do this and play by your own rules, so that we can use a simpler api. Even if the language does not have built-in support for it, it will still simplify the situation, since you can easily break down operations.

+1
source share

What can I do in one full Turing language, which I can do in any other Turing full language.

So, I interpret your question for reading, is it as easy to write a reliable and scalable C ++ application as it is in Erlang?

The answer to this is very subjective. It’s easier for me to write it in C ++ for the following reasons:

  • I have already done this in C ++ (at least three times).
  • I do not know Erlang.
  • I read a lot about Stackless Python, which feels to me like a multi-user match-based multi-tasking system in python, but of course python is written over C.

Having said that. If you already know both languages ​​and you have a certain problem, you can make the best choice based on all the information that you have at hand.

+1
source share

The main β€œproblem” with C (or C ++) for writing reliable and simple extension programs is that you can do something in C. so the first step would be to write a simple structure that limits only a bit. still good programmers do it.

in this case, the restrictions will basically be simplified to define a β€œprocess” at any isolation level that you want. fork() has a reputation for being slow, and threads also need considerable time to appear, so you can use collaborative multitasking, which can be much more efficient, and you can even make it proactive (I think that what Erlang does). For multi-core performance, install a thread pool and make all of them complete to complete tasks.

another important part is to create an appropriate library of immutable data structures, so using them (instead of the standard library), your functions will (basically) be without side effects.

it’s just a matter of installing a good messaging and futures API ... not easy, but at least it doesn't look like changing the language itself.

0
source share

All Articles