News for hackers. Stuff that matters.
Re:Why Concurrency Is Hard by jedberg on Monday November 09, 2020 @08:55PM (#25042101)
The best way to make concurrency easier is to avoid it in the first place. This requires you to think about how correct your data really needs to be.

For example, a bank balance. Most people would assume that bank balances must always be correct. But this isn't really true. Back in the days when people wrote checks, your bank balance was almost never accurate -- it was on you to keep a local register and know your balance, and if you shared the account with someone else, to reconcile with them frequently. ATMs also use eventual consistency. When you take out $300 from the ATM, it attempts to update the balance, but it will let you take the money out if the bank is unavailable. Because the bank is willing to risk $300 that you aren't overdrawn. In most cases the "eventual" part is nearly instantaneous so you don't notice, but it doesn't actually have to be.

So the number one way to make concurrency easy is to avoid it altogether.

Re:Why Concurrency Is Hard by nemo1618 on Monday November 09, 2020 @09:24PM (#25042275)
One of the unfortunate consequences of Go "making concurrency easy" is that many more concurrent programs are now being written by amateurs, with predictable results. This feels like a Hickey-an "simple vs. easy" dichotomy -- what would a language look like that tried to make concurrency simple, rather than easy?
Re:Why Concurrency Is Hard by weehoo on Monday November 09, 2020 @10:38PM (#25042610)
I’ve found Elixir (+Erlang/OTP) to have some incredibly powerful primitives that make it fairly simple to develop concurrent programs.

OTP underpins WhatsApp, Facebook Messenger, and Discord. People have been building very cool high availability embedded Linux projects using the Nerves framework. It’s very good for certain types of concurrent programs.

It won’t take over HPC simulation any time soon, but most of us aren’t working at Sandia, Oak Ridge, etc. Its great for systems that should naturally scale out but don’t map naturally to a GPU. For systems that want to scale up but are forced to scale out due to frequency limits, it’s not as good as C++ written with uArch in mind.

Re:Why Concurrency Is Hard by bcrosby95 on Monday November 09, 2020 @11:24PM (#25042797)
I like Erlang/Elixir but I still see a lot of code with obvious race conditions.

The difficult part I find with Elixir is that processes have a lot of roles: fault isolation, concurrency, synchronization, garbage isolation, maybe more. I've had projects where it's difficult to line these up - one design would be ideal for fault isolation, but it forces expensive copies to be made, so I can't use that design because it completely tanks performance.

Re:Why Concurrency Is Hard by elmo2you on Tuesday November 10, 2020 @06:30AM (#25044782)
> I like Erlang/Elixir but I still see a lot of code with obvious race conditions.

Race conditions? Are you sure? AFAIK, that's pretty much impossible in Erlang/Elixir.

I do get with what you are saying with the second part of your post. That can indeed become an issue sometimes. Certainly one that I've struggled with myself, especially when things were still new to me.

But in my experiences, all those (apparent) conflicts/challenges can be mitigated/solved with proper architecture. Granted, that takes experience, which not all programmers may have (yet).

At the end of the day, programming is a skill and (inexperienced) programmers can always dig themselves a hole, in any language. Elixir is not a silver bullet, that magically solves problems without having to work (hard) on finding the right solution/architecture for a given (complex) problem. Still, in my experience, Elixir makes large/complex distributed systems, and in particular concurrency, a heck of a lot easier than it used to be (for me).

#jm2c

Re:Why Concurrency Is Hard by bcrosby95 on Tuesday November 10, 2020 @10:49AM (#25047258)
Anytime the validity of an operation depends upon the state of multiple processes you need to make sure you aren't creating a race condition, and depending upon your solution you might introduce a chance of deadlocks or timeouts.

If it's just 2 processes then it's pretty easy: process 1 asks process 2 to modify itself, then process 1 modifies itself. However, this can lead to deadlocks/timeouts if both P1 and P2 are attempting to perform this operation at the same time.

And once you're into 3 or more processes, message passing as a method of synchronization breaks down.

Ideally you avoid this stuff with your design. But since processes fill so many roles you can't always avoid it.

Re:Why Concurrency Is Hard by CyberDildonics on Monday November 09, 2020 @09:20PM (#25042259)
Delayed syncing is not the same as "avoiding concurrency altogether" or having data be 'less correct'. Those aren't even simplifications for relaxing the latency of synchronization, they aren't correct descriptions at all.
Re:Why Concurrency Is Hard by jedberg on Monday November 09, 2020 @09:49PM (#25042396)
The point is in a lot of cases where you think you need synchronization you really don't.
Re:Why Concurrency Is Hard by mannykannot on Monday November 09, 2020 @09:59PM (#25042446)
Yet your example is not one of them - with accounts, the sequence of states must converge on a consistent history as they recede into the past.

Eventual consistency comes with it own set of counter-intuitives, and is a multiplier of possible states a system could be in. it is generally not a complication we would choose, but something we must cope with to do things that would otherwise not be feasible.

Re:Why Concurrency Is Hard by CyberDildonics on Monday November 09, 2020 @09:54PM (#25042420)
My point was that your simplifications were not correct. Also synchronization is going to happen at some point or there wouldn't be any problems to talk about. Synchronization is what it all comes down to.