News for hackers. Stuff that matters.
Re:Why has CPU frequency ceased to grow? (2014) by VHRanger on Wednesday February 21, 2018 @07:48AM (#16429037)
How is that an example an improvement over c++? C++ has had pragmatic omp parallel for for two decades
Re:Why has CPU frequency ceased to grow? (2014) by ta2384428 on Wednesday February 21, 2018 @08:48AM (#16429377)
I'm not familiar with OMP, so please forgive me if I'm incorrect - but OMP from my quick search appears to be thread based, while go routines are much lighter weight than threads. They have their own scheduler - which like most things is both good and bad depending on what you want them for. If you use them as intended, the internal scheduler is a great design decision. This means I can happily spawn 10,000 without concern.

Additionally, combining them with the power of channels makes quick work of many tasks. Channels of course can be implemented in C++ too, but having the compiler take care of it for you with additional tools such as the race detector is very handy.

For a large set of problems, they are very nice to work with.

Re:Why has CPU frequency ceased to grow? (2014) by pjmlp on Wednesday February 21, 2018 @10:21AM (#16430043)
You can do the same in C++ on Windows with PPL, UNIX/Windows with Intel TBB, or any of the fiber/co-routine libraries.

Then there is the ongoing work to add async/await patterns into C++20.

Re:Why has CPU frequency ceased to grow? (2014) by quadcore on Wednesday February 21, 2018 @10:34AM (#16430143)
As a matter of fact, you can do the same in assembly if you want to.

Notice how you can always have that answer when it comes to programming languages: you can do the same in. The point is that, the way it's made in go, is awfully handy.

Re:Why has CPU frequency ceased to grow? (2014) by pjmlp on Wednesday February 21, 2018 @11:52AM (#16430823)
I hardly see a difference from

    go func () { }
and

    Task.Run(() => { })
With the benefit that on the latter example, the runtime allows me to customise how scheduling is done.
Re:Why has CPU frequency ceased to grow? (2014) by quadcore on Thursday February 22, 2018 @02:52AM (#16435980)
Are those Tasks coroutines? If yes, do they yield on any sleeps?

These aspects are key to goroutines.

Re:Why has CPU frequency ceased to grow? (2014) by pjmlp on Thursday February 22, 2018 @03:43AM (#16436175)
Yes they do, they are the building blocks for async/await, get a thread allocated from a thread pool when running, and you can control how the scheduling takes place, by providing your own scheduler implementation.
Re:Why has CPU frequency ceased to grow? (2014) by ta2384428 on Thursday February 22, 2018 @08:54AM (#16437520)
That is pretty cool, C++ has come a long way since I used it last about 15 years ago.

It seems like both languages are equally capable here, with C++ having more power and foot guns when required as usual.

Re:Why has CPU frequency ceased to grow? (2014) by pjmlp on Thursday February 22, 2018 @01:25PM (#16439937)
The code snippet example I wrote was actually .NET with TPL.

C++ with PPL on Windows, would be

    task<T> handle = create_task([] { /* ... */ });
And with standard C++

    future<T> handle = std::async(std::launch::async, [] { /* ... */ });
In both cases, with C++20 it will be possible to co_await handle, which you can already play with on clang and VC++.
Re:Why has CPU frequency ceased to grow? (2014) by creato on Wednesday February 21, 2018 @10:59AM (#16430350)
Every OpenMP implementation I know of uses a thread pool, and dispatches parallel work to it.

This is probably exactly the same behavior as goroutines.

Re:Why has CPU frequency ceased to grow? (2014) by Const-me on Wednesday February 21, 2018 @09:45PM (#16434788)
OMP is only good for CPU bound code. You try to do IO inside OMP parallel section, and you’ll put the whole OS thread to sleep. The OS kernel will likely reschedule some other thread on that hardware thread, but that rescheduling is an expensive process.

Goroutines and .net tasks allow a nice mix of CPU bound and IO bound code. While a goroutine/task is waiting for IO or something else to complete (timer in this example), the runtime will immediately use the hardware thread for some other task, without OS involved.