News for hackers. Stuff that matters.
Re:Rust solves the problem of incomplete Kernel Linux API docs by helltone on Saturday August 31, 2024 @12:37PM (#41409985)
I didn't know rust was able to tell when a method is thread safe. Where can I read more about that/try it out?
Re:Rust solves the problem of incomplete Kernel Linux API docs by dagmx on Saturday August 31, 2024 @12:47PM (#41410079)
It’s probably more correct if I say that data types themselves are thread safe or not.

https://doc.rust-lang.org/nomicon/send-and-sync.html

So therefore a function can’t do things that invalidate that type level contract.

Re:Rust solves the problem of incomplete Kernel Linux API docs by remexre on Saturday August 31, 2024 @12:41PM (#41410028)
Send and Sync are the keywords to search for.
Re:Rust solves the problem of incomplete Kernel Linux API docs by metaltyphoon on Saturday August 31, 2024 @12:40PM (#41410009)
Isn’t anything with Arc thread safe?
Re:Rust solves the problem of incomplete Kernel Linux API docs by ninkendo on Saturday August 31, 2024 @01:09PM (#41410245)
No. Just because something’s behind an Arc<T> doesn’t mean two threads can hold it at once. Arc just ensures that it is freed (dropped) when no threads are using it any more. T itself has to be Send+Sync for Arc to be.

To a first approximation, Arc<Mutex<T>> is what you want when you want a blob of mutable stuff to just work between threads, but you still have to worry about terrible performance if you hold the mutexes too long, etc. (Not to mention mutexes are just slower in general than having types which are natively Send+Sync.)

Re:Rust solves the problem of incomplete Kernel Linux API docs by jpc0 on Saturday August 31, 2024 @03:04PM (#41411066)
> Not to mention mutexes are just slower in general than having types which are natively Send+Sync

Without knowing the implementation, how would you know this statement is true?

I could just stick the Arc<Mutex<T>> within my abstraction and say it is send+sync and it would have the exact same performance, and that might be the most efficient solution possible on the given hardware.

Re:Rust solves the problem of incomplete Kernel Linux API docs by ab5tract on Saturday August 31, 2024 @12:41PM (#41410025)
Telling when a thing is thread safe is hardly the same as telling when something isn’t.
Re:Rust solves the problem of incomplete Kernel Linux API docs by aaomidi on Saturday August 31, 2024 @12:40PM (#41410016)
Race conditions within rust are technically impossible :)
Re:Rust solves the problem of incomplete Kernel Linux API docs by jrpelkonen on Saturday August 31, 2024 @12:45PM (#41410059)
Safe Rust prevents data races, but not race conditions in general.
Re:Rust solves the problem of incomplete Kernel Linux API docs by CryZe on Saturday August 31, 2024 @01:39PM (#41410429)
Though arguably, the fact that in order to mutate data from multiple threads, the compiler,forces you to use some synchronization primitive, results in you having to think about how you are going to synchronize access, which should lower the chance of race condition bugs overall.
Re:Rust solves the problem of incomplete Kernel Linux API docs by tialaramex on Saturday August 31, 2024 @01:53PM (#41410526)
The analogy I find helpful for this is, you let the cat out your front door and close it. You walk to the back door and close that too.

A race condition (which safe Rust can have) is a normal phenemenon in our world. If we put the cat out the front door, then walk to the kitchen and close that door by the time we reached the back door maybe the cat had run around the outside of the building and come inside again, closing the doors in the wrong order introduced the opportunity for a race - be very careful.

A data race (which safe Rust does not have) is a weird thing caused by the mismatch between how you think the computer works and how it actually works. What happens if Alice tries the put the cat out the front door at the same time Bob tries to put it out the back door? Well, in the real world that cannot happen, either Alice has the cat or Bob does. But for many languages† this sort of nonsense can happen and when it does that's a disaster

† In safe Rust it can't happen, in Java, OCaml and Go it can happen, but it may not be a disaster (the details are different for each, it is a bug though).

Re:Rust solves the problem of incomplete Kernel Linux API docs by irundebian on Saturday August 31, 2024 @03:10PM (#41411113)
Interesting analogy.
Re:Rust solves the problem of incomplete Kernel Linux API docs by aaomidi on Saturday August 31, 2024 @03:35PM (#41411317)
That’s why I said inside rust. If you bring in external factors then of course it can/will happen.
Re:Rust solves the problem of incomplete Kernel Linux API docs by sixfiveotwo on Saturday August 31, 2024 @01:57PM (#41410560)