Article View: comp.arch
Article #61Re: Optimization by programmers
From: MitchAlsup
Date: Mon, 12 Oct 2026 18:37
Date: Mon, 12 Oct 2026 18:37
85 lines
4203 bytes
4203 bytes
cross@spitfire.i.gajendra.net (Dan Cross) posted: First off: thank you dan for a well done explanation. > In article <1791742457-5857@newsgrouper.org>, > MitchAlsup <user5857@newsgrouper.org.invalid> wrote: > > > >Terje Mathisen <terje.mathisen@tmsw.no> posted: > > > >> Dan Cross wrote: > >--------- > >> > >> My old asm/C brain _knows_ that a slice of something with a known > >> address and total length is effectively the same thing as an unmutable > >> array. > > > >Can I get a definition of what mutable in Rust means ?? > --------snip of what I understand clearly------------ > > So this will fail to compile: > > ? let mut foo = something(); > ? let foomut = &mut foo; // Ok: only mutable > ? let barmut = &mut foo // Fail: a mut ref to foo exists Is this supposed to work across threads ?? so, only 1 thread has write access at any given point in time. If so, how does one thread hand-off mutability to another ?? --------------snip again-------- > > By default, all assignments in Rust have _move_ semantics: after > the assignment, the source is considered destroyed, and any > references to it are no longer valid. That's why one can assign > to `foo` and on line 5 and then take a mut reference to it on > line 7; the assignment on 5 implicitly dropped the original > `foo` object created on line 1 and replaced it with a new > object, so the mut reference it created on line 3 is invalid; > an attempt to use it subsequently would fail to compile. This is clever. > One can define a `copy` operator for types that should not have > move semantics; this is usually applied to trivial types (like > integers). > > One may ask, "why bother with all of this stuff?" and the answer > is that Rust is designed for a multicore world. There is one > other wrinkle here that gives Rust a lot of power, and that's > how all of this stuff interacts with data races: safe Rust code > is data race free. See question above. > Rust does not mandate a particular shape or type of (software) > thread, but because of the "mut ref ^ immut ref" rule, enforced > by the borrow checker at compile-time, safe Rust programs cannot > race on access to data, even in the face of multithreading. > > Rust handles this by exposing two "marker traits", `Sync` and > `Send`. To quote the _Rustinomicon_, "A type is `Send` if it is > safe to send it to another thread" and "A type is `Sync` if it > is safe to share between threads (T is `Sync` if and only if > `&T` is `Send`)." That is, a type can be _shared_ between > threads if it is safe to send an immutable reference to it from > one thread to another, and the compiler can check borrows > against the lifetimes of objects, hence, can detect data races > _statically, at compile time_. > (https://doc.rust-lang.org/nomicon/send-and-sync.html) > > Those of us familiar with writing multithreaded programs will > recognize the power of these constructs: these rules, taken > together, statically eliminate entire categories of common > memory and concurrency problems. > > Anyway, that what "mutable" means, in a nutshell, and why it is > important. Thanks again for a complete explanation. > - Dan C. >
Technical Details
Message-ID:
<1791830267-5857@newsgrouper.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!newsgrouper.org!.POSTED!not-for-mailReferences:
<1177fdi$26ea4$1@dont-email.me> <11a6870$41j$1@reader2.panix.com> <11a6a6h$37i1n$1@dont-email.me> <1791742457-5857@newsgrouper.org> <11aiv39$bpk$1@reader2.panix.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!newsgrouper.org!.POSTED!not-for-mail From: MitchAlsup <user5857@newsgrouper.org.invalid> Newsgroups: comp.arch Subject: Re: Optimization by programmers References: <1177fdi$26ea4$1@dont-email.me> <11a6870$41j$1@reader2.panix.com> <11a6a6h$37i1n$1@dont-email.me> <1791742457-5857@newsgrouper.org> <11aiv39$bpk$1@reader2.panix.com> Date: Mon, 12 Oct 2026 18:37:47 GMT Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-ID: <1791830267-5857@newsgrouper.org> Injection-Info: newsgrouper.org; mail-complaints-to="newsgrouper@yahoo.com"; posting-account=user5857 Injection-Date: Mon, 12 Oct 2026 18:37:47 GMT User-Agent: Newsgrouper/0.9.0