News for hackers. Stuff that matters.
Re:Even in Go, concurrency is still not easy by jshen on Thursday September 03, 2020 @01:25AM (#24361006)
I’ll bet your Go code, if it isn’t trivial, has race conditions all over and you just don’t realize it.
Re:Even in Go, concurrency is still not easy by naikrovek on Thursday September 03, 2020 @11:11AM (#24364787)
It's not trivial and I found a lot of races, yes, but I refactored over a couple days to completely isolate work within a goroutine so that data is only passed in and out of them via channels, and with that all races went away. The tool has been used in production extensively for a couple of years now, converting 3D model files from one format to another, and it's running great, and very fast as well.

So, you're right, but it has been addressed.

Re:Even in Go, concurrency is still not easy by xmprt on Thursday September 03, 2020 @02:02AM (#24361154)
Can't that be said for most languages? Is there anything special that other languages do to make race conditions less likely than they are in Go?
Re:Even in Go, concurrency is still not easy by pizza234 on Thursday September 03, 2020 @02:13AM (#24361204)
I believe it's correct that that can be "said for most languages".

Since you're asking, Rust's ownership/type system, for example, has checks in place that prevent at least some classes of concurrency errors.

For example, you can't directly modify a variable from multiple threads, due to the so-called "move" rules:

    let mut myvar = vec![];

    thread::spawn(move || {
        myvar.push(1);
    });

    myvar.push(1); // can't do this; variable has been moved
Re:Even in Go, concurrency is still not easy by ben0x539 on Thursday September 03, 2020 @02:37AM (#24361365)
I think Go invites mistakes like this being made over and over, because (in my subjective opinion as someone who writes a lot of Go at work but isn't extremely happy about that) you have to write out the basic low-level concurrency patterns over and over, because the language tries to resist abstraction.

In other langs I'd expect to see this code use a generic map-reduce/parallel map helper function or something like that, but in Go people seem to be happier writing for-loops and spawning goroutines by hand every time.

Re:Even in Go, concurrency is still not easy by iainmerrick on Thursday September 03, 2020 @03:44AM (#24361702)
A lot of people are making tangential points in this discussion (“concurrency is always hard!”) but you’ve put your finger on the key point.

Concurrency is hard, and one fairly successful approach is to provide battle-tested libraries for these high-level use cases (“run M functions with max parallelism N”). Go gives you low-level concurrency tools, but actively resists the kind of abstraction that would let you make reusable high-level tools, so that robust library doesn’t exist.

It’s a strange lack, as it’s meant to be a concurrency-focused language, and the standard library is absolutely terrific in other areas (eg networking and encryption).

Re:Even in Go, concurrency is still not easy by apta on Thursday September 03, 2020 @02:28PM (#24367113)
It just shows golang designers lack of experience in language design (it's stuck in the 70's). They may have written a lot of code, but it doesn't automatically make them good language designers.
Re:Even in Go, concurrency is still not easy by ben0x539 on Friday September 04, 2020 @01:53AM (#24372107)
I'm not really sure about this. I think the language they designed has the properties they desired, in that they consciously forewent a lot of potential benefits because some notion of simplicity is more important to them. So in that sense I think they were successful at designing a language.

Like some other comment here says, you run into bugs like this early on and they're not necessarily show-stoppers. Maybe keeping the language simple and ensuring that most code is readable if you only know the language and the stdlib (and not some fancy concurrency library) is worth the occasional bug?

Of course that doesn't necessarily mean that Go is the language I want to use for every use case under the sun, but that probably wasn't a goal of Go to begin with.

Re:Even in Go, concurrency is still not easy by apta on Friday September 04, 2020 @11:50AM (#24376040)
> I think the language they designed has the properties they desired

That's a tautology though :) Of course any language designer will design a language according to the properties he/she desires.

> you run into bugs like this early on

Not necessarily. Race conditions are hard to find. It's established that "simplicity" is not a straight forward metric to measure. Having a simplistic language just means that complexity is being pushed on the programmer, since most non-trivial programs are complex by definition.

Regardless of what the goals of golang were (they kept changing their definition of "systems language"), the fact that it's being pushed for almost everything, due to hype and fad driven development, and the inexperience of many programmers, is an issue. It's almost ironic that golang is used more outside of google than in.

Re:Even in Go, concurrency is still not easy by ben0x539 on Friday September 04, 2020 @06:05PM (#24379357)
> That's a tautology though :) Of course any language designer will design a language according to the properties he/she desires.

Eh, you can just fail, too, no? Like I could sit down and set myself the goal of designing a language that achieves goal X while staying under complexity limit Y (by whatever measurement), and then end up having to compromise on either of them because I can't quite figure out a good way to achieve a particularly tricky part of X without adding a lot more complexity than I initially expected. Or I could decide I want to design a language that's portable across many CPU architectures but inadvertently bake in a lot of x86isms that make it awkward/inefficient to implement elsewhere.

> Not necessarily. Race conditions are hard to find. It's established that "simplicity" is not a straight forward metric to measure. Having a simplistic language just means that complexity is being pushed on the programmer, since most non-trivial programs are complex by definition.

Ah, I didn't mean that concurrency bugs are quickly found or solved. I definitely agree with the just-moving-the-complexity-around part. I just meant that soon after getting started with Go, you'll probably have run into a bunch of concurrency bugs already and developed the kind of mental scarring and automatic averse reactions to certain concurrency situations that'll let you cope and still get things done despite it being clearly suboptimal.

> the fact that it's being pushed for almost everything, due to hype and fad driven development, and the inexperience of many programmers, is an issue.

But this is a kind of success too, isn't it? Presenting your solution to a problem in a way that appeals to enough "inexperienced" people to create the hype/fad isn't trivial, so they must have been doing something right. I don't think it's just a case of "$bigcorp does it, so it's cool", plenty of $bigcorp languages or technologies don't really catch on, let alone on Go's scale.

I think there really is a niche where Go is the best solution (or at least a significant local maximum), even if that is only "'inexperienced' programmers can get started with, say, highly concurrent http services", it's still _something_.

(Again, disclaimer: I use Go at work and I like to give my (non-google) employer and my coworkers enough credit to think that it's not just because of hype/fad, so I may be biased.)

Re:Even in Go, concurrency is still not easy by IshKebab on Thursday September 03, 2020 @07:07AM (#24362800)
> Is there anything special that other languages do to make race conditions less likely than they are in Go?

Yes, other languages provide you with more tools than the basic nuts and bolts. For example a language might provide you with a "parallel for" primitive that is well tested.

The issue is not exactly that Go's concurrency stuff is bad, it's just that it doesn't give you much help so you have to implement it all yourself. Also the lack of generics means it is difficult to write libraries for this stuff.

Re:Even in Go, concurrency is still not easy by ed25519FUUU on Thursday September 03, 2020 @11:03AM (#24364710)
The frustrating part is that the standard lib is just good enough that you also don’t tend to get good adoption for third party libraries, which could easily provide better abstractions.
Re:Even in Go, concurrency is still not easy by continuational on Thursday September 03, 2020 @02:10AM (#24361190)
Some languages emphasize persistent data structures, or even enforce immutability, which means you can only introduce race conditions via explicit concurrency. That's a lot less surface area for bugs.
Re:Even in Go, concurrency is still not easy by johnisgood on Friday September 04, 2020 @11:19AM (#24375694)
Yep, Ada/SPARK: https://docs.adacore.com/spark2014-docs/html/ug/en/source/co...

Search for "race condition", or just "race".

This section in particular is about preventing data races: https://docs.adacore.com/spark2014-docs/html/ug/en/source/co...

This one is about preventing race conditions: https://docs.adacore.com/spark2014-docs/html/ug/en/source/co...

Re:Even in Go, concurrency is still not easy by thesuperbigfrog on Thursday September 03, 2020 @03:25AM (#24361593)
Clojure uses immutable data structures and software transactional memory:

https://clojure.org/about/concurrent_programming

Re:Even in Go, concurrency is still not easy by jshen on Friday September 04, 2020 @03:15AM (#24372520)
I love clojure, and I’ve written some high concurrency production apps in it. Concurrency is still hard in clojure, and that’s assuming all of your state and logic can live in a single process. That assumption usually doesn’t hold, and then concurrency gets way harder.
Re:Even in Go, concurrency is still not easy by papaf on Thursday September 03, 2020 @01:33AM (#24361036)
Go has a built in race detector that most teams run during CI.

[1] https://golang.org/doc/articles/race_detector.html

Re:Even in Go, concurrency is still not easy by ben0x539 on Thursday September 03, 2020 @02:30AM (#24361314)
This roughly detects data races, not all race conditions.
Re:Even in Go, concurrency is still not easy by gpderetta on Thursday September 03, 2020 @03:49AM (#24361729)
And not all possible data races.
Re:Even in Go, concurrency is still not easy by andonisus on Thursday September 03, 2020 @11:22AM (#24364898)
This does not run if you have more than 10K go routines :(