3 ms·
First, that statement was not present in grandparent's post when the parent posted his message. Second, that premise is completely untrue. Go, and most other l
by 4ad 11y ago
First, that statement was not present in grandparent's post when the parent posted his message.
Second, that premise is completely untrue. Go, and most other languages give you more-or-less orthogonal primitives and let you combine them. It's okay for your types not to be thread safe, if by combining them with some other primitive you can make them thread safe.
Every other language does this. Some offer you a concurrent map along with a non-concurrent map. For many reasons I won't get into, Go only has one kind of map and lets the user do the rest (which is an extremely easy idiom in Go). Note that even though many languages conveniently offer concurrent maps, no languages with mutable state that I know of offer concurrent integer and concurrent structs. The user is still responsible for ensuring the safety of those.
This is perfectly fine because the grandparent's premise is wrong. In concurrent language, by far the most common case is by data to be owned by a goroutine/thread/whatever. It's very easy to reason about code this way, and it's the way you are encouraged to write code.
Only when you need to share data you need to worry about concurrency-safety, and in that scenario you have available all the tools to ensure it.
- lambda_cube 11y ago> no languages with mutable state that I know of offer concurrent integer and concurrent structs Java does for integer http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html http://docs.oracle.com/javase/8/docs/api/java/util/concurren... You can find similar classes in the java.util.concurrent.atomic package. http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/package-summary.html http://docs.oracle.com/javase/8/docs/api/java/util/concurren... I'm not sure what requirements you have for a concurrent struct, but Java has classes to atomically manipulate int and long fields of a class. I'm not arguing your general point (in fact, I agree with it), I'm just supplying some extra information of a language that you apparently don't know.