←back to thread

271 points mithcs | 2 comments | | HN request time: 0.448s | source
Show context
woodruffw ◴[] No.45953391[source]
Intentionally or not, this post demonstrates one of the things that makes safer abstractions in C less desirable: the shared pointer implementation uses a POSIX mutex, which means it’s (1) not cross platform, and (2) pays the mutex overhead even in provably single-threaded contexts. In other words, it’s not a zero-cost abstraction.

C++’s shared pointer has the same problem; Rust avoids it by having two types (Rc and Arc) that the developer can select from (and which the compiler will prevent you from using unsafely).

replies(13): >>45953466 #>>45953495 #>>45953667 #>>45954940 #>>45955297 #>>45955366 #>>45955631 #>>45955835 #>>45959088 #>>45959352 #>>45960616 #>>45962213 #>>45975677 #
saurik ◴[] No.45953667[source]
I'd think a POSIX mutex--a standard API that I not only could implement anywhere, but which has already been implemented all over the place--is way more "cross platform" than use of atomics.
replies(2): >>45953901 #>>45957239 #
woodruffw ◴[] No.45953901[source]
To lift things up a level: I think a language’s abstractions have failed if we even need to have a conversation around what “cross platform” really means :-)
replies(2): >>45958139 #>>45958197 #
jhatemyjob ◴[] No.45958197[source]
If that's the bar, what language's abstractions haven't failed?
replies(1): >>45960695 #
1. ruined ◴[] No.45960695[source]
wasm and lambda calculus
replies(1): >>45967019 #
2. ◴[] No.45967019[source]