I have a piece of code I need to lock so that only one thread can enter the critical area at a time. My program is written in Kotlin and run on Android.
I have declared a singleton like so
object MySingleton {
fun critical() {
synchronized(this) {
// critical section here
}
}
}
My question is - is this correct in that this will definitely only allow just one thread in?