Live data from Hacker News

Fearless concurrency with Rust

blog.rust-lang.org

91–100 of 186 posts

Re: Fearless concurrency with Rust

#91

Earlier quoted context omitted.

> Sorry if I'm missing something obvious, but how do these locks stop a deadlock from happening? This is the difference between a data race and a race condition. We can't generally prevent deadlocks, I would imagine that's (like all race conditions) is an unsolvable problem at the language level. Maybe some PhD will prove me right or wrong, though...

That said, the ergonomics of the mutex design and the ownership system would probably eliminate most of the race conditions I've seen. Lock ordering can be effectively established by nesting mutexes: e.g. `Mutex )>` allows you to establish that any locking of Y has already locked X.

Yeah, I've thought about this approach in the past. One problem is that it requires you to acquire the same locks in the same order. That is, if you had Mutex)>)>, you couldn't acquire X, then Z, without first acquiring Y, but it would be perfectly safe to do so.

(Although, come to think of it, you can probably work around that with some cleverness; e.g., you could provide the option to access either the data protected by the Mutex or the next Mutex in the sequence through &mut; whichever you chose, you couldn't access the other until you were through with the children. You still have to keep the mutexes structurally in a linked list, though, which is obviously not ideal for all situations. And you still need to deal with the fact that the reference to the first Mutex must be an &-reference, hence can be replicated indefinitely, which allows you to subvert the ordering guarantees; but this was already a problem, and I think there are some clever ways around this using rank-2 lifetimes).

Re: Fearless concurrency with Rust

#92
post #90

Earlier quoted context omitted.

Just looked at eventual. It seems really interesting. I looked at Rust's std Future and was turned off by the fact that is blocking.

Rust is blocking, there was mio crate which brought non-blocking IO operations.

Well, Rust doesn't have any opinions regarding blocking or not. Currently, std::io implements blocking IO, but as you pointed out, Rust allows libraries to implement non-blocking / async paradigms.

Re: Fearless concurrency with Rust

#93
post #3

This post observes that > the same tools that make Rust safe also help you tackle concurrency head-on. The tools that make Rust safe, in this instance, being its ownership type system. Why on earth should that be the case? Why would ownership types make concurrency easier? The post gives plenty of in-depth answers to this question, but to my mind it misses the bigger picture. The big-picture reason why ownership type…

For anyone interested in session types, we are currently working on implementing a library for them, in Rust[0]. However, as you point out, Rusts types are affine, not linear, so we're also working on a compiler plugin for Rust that let's you track protected types and make sure they aren't dropped, letting you sort of emulate linear types[1]. Most of this is still in a pretty early state (neither actually compile at the moment), and there are some fundamental problems with the plugin (it's impossible afaik for compiler plugins to examine external crates), but someone might find it interesting. Eventually, our goal is to use these tools to solve some concurrency problems in Servo.

[0] https://github.com/Munksgaard/rust-sessions [1] https://github.com/Manishearth/humpty_dumpty

Re: Fearless concurrency with Rust

#94
post #90

Earlier quoted context omitted.

Rust is blocking, there was mio crate which brought non-blocking IO operations.

Well, Rust doesn't have any opinions regarding blocking or not. Currently, std::io implements blocking IO, but as you pointed out, Rust allows libraries to implement non-blocking / async paradigms.

"Rust is so low-level that IO is a library concern, not a language concern," as I like to say.

Re: Fearless concurrency with Rust

#95

Earlier quoted context omitted.

Well, Rust doesn't have any opinions regarding blocking or not. Currently, std::io implements blocking IO, but as you pointed out, Rust allows libraries to implement non-blocking / async paradigms.

"Rust is so low-level that IO is a library concern, not a language concern," as I like to say.

But standard IO is blocking, correct?

But Rust being so low level to not care about IO is Awesome :)

Re: Fearless concurrency with Rust

#96
Can someone please write a Clojury lisp that compiles to Rust without immutability (by default) and concurrency primitives, since thread safety is guaranteed by the rust compiler?

I love Clojure, but this would be a completely different beast, a crazed DRAGON probably.

PS: I want a Dragon

Re: Fearless concurrency with Rust

#97

Earlier quoted context omitted.

> (an explicit primary design goal, to the point where the Go compiler must be written to read each file exactly once[0], no more). Same in Rust. Thanks to the module system, the Rust compiler never rereads a file more than once. > [1] I'd need to think about this, but I don't think it'd be difficult to detect this statically[2] at compile-time and enforce that stack-allocated rvalues into channels are never used aga…

> > (an explicit primary design goal, to the point where the Go compiler must be written to read each file exactly once[0], no more). > Same in Rust. Thanks to the module system, the Rust compiler never rereads a file more than once. As I said right at the beginning of my post, I'm not trying to compare Rust and Go directly, because I don't think that's meaningful. I'm explaining why these particular features would b…

You outlined why they shouldn't be compared because they are different and outlined differences. The response (from one of the rust devs, if I'm correct) explained how some of your purported differences weren't actually different. The response wasn't ignoring your first line, it was explaining how portions of your evidence backing up that first line were factually incorrect.

Re: Fearless concurrency with Rust

#98
post #95

Earlier quoted context omitted.

"Rust is so low-level that IO is a library concern, not a language concern," as I like to say.

But standard IO is blocking, correct? But Rust being so low level to not care about IO is Awesome :)

We're starting off by only having blocking IO in the standard library, yes.

Re: Fearless concurrency with Rust

#99

Earlier quoted context omitted.

> A managed heap I'm not sure what you mean by this, but when I hear "managed heap" I think of heap memory managed by a garbage collector. This is not a feature of Rust. > emphasis on the use of functional constructs Rob Pike wrote (unavoidably, because of the lack of generics) crippled versions of map and reduce for Go and declared that the almightly for loop was superior. I don't think an emphasis on the use of fun…

On the rejection-of-OOP thing; I agree that seems like the biggest similarity between Go and Rust, but even then, the major replacements for those features are completely different – Rust's traits are more like typeclasses and C++ templates (to some extent) than they are to Go's interfaces (though "trait objects" are like interfaces, but used less often). It also seems like Rust will eventually add some form of more…

> It also seems like Rust will eventually add some form of more traditional OOP features like inheritance, because the servo project would like such things to implement the DOM

There's been a great community and core team effort to design small, orthogonal language features (or extensions to existing features) that can be used to regain the performance + code reuse benefits one gets from using inheritance, without all the associated warts. The DOM/Servo problem is a tough one and it's going to be very interesting to see if Rust can solve it without resorting to the blunt instrument of inheritance.

Here's an example from last year of such an attempt, in RFC form: https://github.com/rust-lang/rfcs/pull/250

Post reply on HN