Conversation

This Tweet was deleted by the Tweet author. Learn more
This also applies to Go but I didn't realize Swift also cut corners in this area. Java has data races but preserves memory safety in their presence. This sometimes means paying some additional performance costs to make sure it only goes quite wrong instead of horribly wrong.
1
2
Replying to and
Not so much "cutting corners" as making tradeoffs. Swift wanted to have a zero-overhead FFI, and it's hard to see how to provide Java level guarantees without a full GC environment and expensive FFI
1
Replying to and
As long as the library is thread safe, the FFI can still be zero overhead. The wrapper would only need to enforce thread safety if the library didn't already provide safe APIs. It would also be possible to have a concept of types that cannot be shared or sent between threads.
3
Rust handles this without a performance cost. The vast majority of types like vectors, hash tables, etc. can be sent between threads (Send trait) and don't need to provide thread safety. Rc<T> is the main exception, with Arc<T> used when atomic reference counting is truly wanted.
2
1
In a language like Swift, far more types would just not be Send and those types would need to explicitly support stealing to support it without a copy. For example, a vector without synchronization can support stealing it to another thread by setting the existing one to 0 length.
1
Swift has value types so those are all be Send, and supporting ownership more would really just mean extending what can be done with value types to include heap allocated data where a shallow copy prevents using the source (move). More flexible borrows would be a separate thing.
1
Show replies