y
05/07/2023, 1:36 PMclass Foo {
private val someConcurrentCollection = //...
fun addToCollection(val s: String) {
if (!checkS(s)) {
return
}
synchronized(this) {
val t = doSomethingToS(s)
someConcurrentCollection.add(t)
}
}
}
fun checkS(s: String): Boolean = //...
I have something that kind of looks like this. does the fact that a thread is currently in the synchronized
block, completely prevents other threads from entering the addToCollection()
function and running checkS()
? same for the other way around, do multiple threads with s
values such that checkS(s) = false
stop 'legitimate' threads from entering addToCollection()
?Joffrey
05/07/2023, 1:44 PMcheckS
. They will only stop at the beginning of the synchronized
block if one thread is already there.y
05/07/2023, 1:44 PMRob Elliot
05/08/2023, 1:49 PMJoffrey
05/08/2023, 2:58 PMy
05/08/2023, 3:02 PM