What happens if I call some method from an `async`...
# coroutines
What happens if I call some method from an
block and inside of this method I use
block? Will it work or I have to use
as stated here https://kotlinlang.org/docs/reference/coroutines/shared-mutable-state-and-concurrency.html#mutual-exclusion ?
synchronized may block the thread
it may be a problem, but not necessary, depending what synchronised code does
So it’ll work with coroutines just like with normal threads?
Coroutines use normal threads
no difference
only problme that with coroutines (suspend funcions) you always expect that this function will not block your thread. synchronised block may be very fast and not a problem, but again, as I said above, it depends what your synchronise block does
if you expect that synchronised block may block for long enough time, than better to use Mutex instead, or as simple solution, just wrap this function to IO dispatcher, so even if it block it will not be a problem for calling thread (especially if it’s Main thread)
Thank you Andrey, that is very helpful!