4 ms·
In Java, there are separate synchronized collections, because acquiring a lock takes time. Normally one uses thread-unsafe collections. Java also gives a very
by nine_k 1y ago
In Java, there are separate synchronized collections, because acquiring a lock takes time. Normally one uses thread-unsafe collections. Java also gives a very ergonomic way to run any fragment under a lock (the `synchronized` operator).
Rust avoids all this entirely, by using its type system.
- noisem4ker 1y agoGolang has a synchronized map: https://pkg.go.dev/sync#Map https://pkg.go.dev/sync#Map
- layer8 1y agoJava has separate synchronized collections only because that was initially the default, until people realized that it doesn’t help for the common cases of check-and-modify operations or of having consistency invariants with state outside a single collections (besides the performance impact). In practice, synchronized collections are rarely useful, and instead accesses are synchronized externally.