Why are there no concurrency keywords (synchronized, volatile) in Kotlin?
Hi everyone! I'm a beginner Kotlin developer transitioning from Java. In Java, I'm used to using the `synchronized` and `volatile` keywords, as well as `synchronized` blocks, to control access to shared resources in multithreaded applications. But when I started writing in Kotlin, I noticed that the language doesn't have these keywords! For example, I tried to write a simple thread-safe counter:
```kotlin
class Counter {
private var count = 0
fun increment() {
// How do I synchronize this method?
count++
}
}
```
In Java, I would write `public synchronized void increment()`, but there's no such option in Kotlin. I found in the documentation that there are `@Synchronized` and `@Volatile` annotations, but that's not the same as keywords. It seems very strange to me that th
No answers yet.
Log in to leave an answer