News for hackers. Stuff that matters.
Re:Concurrent Hello World in Go, Erlang, and C++ by tqh on Monday November 05, 2012 @04:35AM (#4742839)
Funny thing about the C++ example: The API Mindroid implements in C++ from Androids Java API, is actually from BeOS originally where it was C++. It still exists today in Haiku. So Mindroid has gone full circle C++ -> Java -> C++. Here is the Haiku versions for comparison: http://cgit.haiku-os.org/haiku/tree/src/kits/app/
Re:Concurrent Hello World in Go, Erlang, and C++ by DanielHimmelein on Monday November 05, 2012 @06:52AM (#4743071)
Ah ok, I checked the Haiku source and I think this works like the original Binder concurrency stuff (see http://www.osnews.com/story/13674/Introduction_to_OpenBinder...). Android's concurrency framework (as well as Mindroid) is a refined version of Be's concurrency APIs.
Re:Concurrent Hello World in Go, Erlang, and C++ by tqh on Monday November 05, 2012 @06:55AM (#4743080)
Yes, it is like the original Be code. It was for showing the inheritage.
Re:Concurrent Hello World in Go, Erlang, and C++ by DanielHimmelein on Monday November 05, 2012 @06:47AM (#4743062)
Hi that is funny. I knew that Dianne Hackborn brought Binder over to Android from BeOS and Palm. But I did not know that also the concurrency framework is from the Be guys. Thanks for sharing the link :-).
Re:Concurrent Hello World in Go, Erlang, and C++ by gizmomogwai on Tuesday November 06, 2012 @01:38PM (#4749784)
almost like erlang (http://dlang.org/)

  import std.stdio;
  import std.concurrency;

  void world() {
    bool running = true;
    while (running) {
      receive(
        (Tid finished) { writeln("World"); send(finished, true); },
        (OwnerTerminated e) { running = false; }
      );
    }
  }
  void hello(Tid world, Tid finished) {
    for (int i=0; i<1000; i++) {
      write("Hello ");
      send(world, thisTid);
      receiveOnly!(bool)();
    }
    send(finished, true);
  }
  int main(string[] args) {
    auto world = spawn(&world);
    auto hello = spawn(&hello, world, thisTid);
    receiveOnly!(bool)();
    return 0;
  }
Re:Concurrent Hello World in Go, Erlang, and C++ by baobab on Sunday November 04, 2012 @11:43PM (#4742286)
I couldn't bear looking at how bloated C++ implementation is, so I implemented it in C++11 based on boost.fiber library: https://gist.github.com/4015306. Now it looks very similar to Go language code.
Re:Concurrent Hello World in Go, Erlang, and C++ by DanielHimmelein on Monday November 05, 2012 @03:42AM (#4742751)
But I have to admit that Android's concurrency framework is more about message passing and actors than about fibers or coroutines. The fiber implementation is much more readable here.
Re:Concurrent Hello World in Go, Erlang, and C++ by DanielHimmelein on Monday November 05, 2012 @03:33AM (#4742730)
Cool, looks much better :-). Normally, I really like Android's concurrency abstractions, but not for this one :-).
Re:Concurrent Hello World in Go, Erlang, and C++ by Tyr42 on Sunday November 04, 2012 @01:35PM (#4740500)
Hey, I implemented it in C using just posix threads. It's my first time using posix threads, but I think it's not wrong. I tried to copy go's channels. https://gist.github.com/4012855
Re:Concurrent Hello World in Go, Erlang, and C++ by codewright on Sunday November 04, 2012 @01:46PM (#4740556)
Seems pretty reasonable to me. I actually rather like the idea of taking the best of higher level languages that can't work for systems programming and stealing their ideas to the darker realms of C and C++.
Re:Concurrent Hello World in Go, Erlang, and C++ by chrismorgan on Sunday November 04, 2012 @08:17AM (#4739687)
Why make a `chan string` rather than a `chan bool`?

Also, "quiter" would be better spelled "quitter".

It's a good demonstration of how nice Go can be for that sort of thing. Now I just want to see a Rust example.

Re:Concurrent Hello World in Go, Erlang, and C++ by DanielHimmelein on Sunday November 04, 2012 @08:34AM (#4739729)
Oh, you are right with quitter. That is a typo. It will fix it. It used chan string just because it does not matter for this example :-).
Re:Concurrent Hello World in Go, Erlang, and C++ by genwin on Sunday November 04, 2012 @01:11PM (#4740427)
Nice comparison. Anyone can now run the Go version in the Go Playground at http://play.golang.org/p/w0N-ZtBBw_
Re:Concurrent Hello World in Go, Erlang, and C++ by zem on Sunday November 04, 2012 @04:42PM (#4741181)
i miss erlang sometimes. sadly, the things it is good for are not the things i tend to be interested in exploring in my personal projects, but using it at work was a truly wonderful experience.
Re:Concurrent Hello World in Go, Erlang, and C++ by drivebyacct2 on Sunday November 04, 2012 @05:38PM (#4741342)
I think something other than "Hello World" would have been better. "WorldHandler" is awkward. The comparison is neat but do something more classically concurrent. even a simple producer consumer could probably be done with nearly a find and replace.