News for hackers. Stuff that matters.
Re:Rust via its Core Values by catnaroek on Sunday April 03, 2016 @04:49PM (#11417609)
Of course, garbage collection per se doesn't protect you from segfaults. For example, there exist garbage collectors for C. They reclaim unused memory, but you can still cause segfaults if you want to (or are careless).

Automatic memory management (whether done at runtime with a garbage collector, or at compile time as in Rust) frees you from logical memory errors by making them inexpressible. But automatic memory management doesn't guarantee that segfaults won't happen - it only guarantees that they won't matter to the programmer. For example, a garbage collector could deliberately trigger segfaults (by `mprotect()`ing all managed memory) to forcibly pause the mutator during a garbage collection cycle. Every managed thread must install a `SIGSEGV` handler that waits until the collection process is done.

Re:Rust via its Core Values by bogomipz on Monday April 04, 2016 @06:46AM (#11420781)
"For example, a garbage collector could deliberately trigger segfaults (by `mprotect()`ing all managed memory) to forcibly pause the mutator during a garbage collection cycle. Every managed thread must install a `SIGSEGV` handler that waits until the collection process is done."

Interesting, is this actually a common implementation pattern for languages that have a GC built into their run time?

Re:Rust via its Core Values by samth on Tuesday April 05, 2016 @10:16AM (#11430523)
I don't think the exact thing you describe is common, but plenty of garbage collectors use memory protection to implement the write barrier. This is particularly useful when integrating with arbitrary code you don't control, since it will also be affected by memory protection.
Re:Rust via its Core Values by catnaroek on Monday April 04, 2016 @01:35PM (#11423722)
No idea. I haven't read the source code of any serious, production GC. I've only written toy ones.