Hello, I am trying to use mutex in my thread but it does not work because the function lock need an other suspend function and I cannot do that in my thread. Do you have an idea to resolve the problem ?
this is my code :
import kotlin.concurrent.thread
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.sync.Mutexval t1 = thread(start = false, priority = 5)
{
mut.lock()
for(i in 0…10){
i++
}
println(i)
mut.unlock()
}val t2 = thread(start = false, priority = 5)
{
mut.lock()
for(i in 0…10){
i–
}
println(i)
mut.unlock()
}var mut = Mutex()
var i :Int = 0fun main(args: Array) {
t1.start()
t2.start()
t1.join()
t2.join()
}
thanks for your help