Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.43 KB | None | 0 0
  1. import kotlinx.coroutines.runBlocking
  2. import kotlinx.coroutines.sync.Mutex
  3. import kotlinx.coroutines.sync.withLock
  4.  
  5. fun main() {
  6.     val t = TestClass()
  7.     runBlocking { t.m1() }
  8.     println("end")
  9. }
  10.  
  11. class TestClass {
  12.     private val mutex = Mutex()
  13.  
  14.     suspend fun m1() = mutex.withLock(this) {
  15.         println("m1")
  16.         m2()
  17.     }
  18.  
  19.     suspend fun m2() = mutex.withLock(this) {
  20.         println("m2")
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement