https://kotlinlang.org logo
#coroutines
Title
# coroutines
u

ursus

06/28/2020, 11:49 PM
Hi, is
Semaphore
meant to be at application layer? My case it to enforce only 1 caller of synchronization at a time
l

louiscad

06/29/2020, 8:28 AM
If you only want one caller at a time and you know it's not going to change to another number, you want to use
Mutex
instead.
u

ursus

06/29/2020, 8:05 PM
right, it will work, but im confused if there should be such api used in between my business logic which syncing basically is
but I guess people use Channels for data flow, and theyre also a coroutine primitive, so ..
may I ask, difference with coroutine Mutex or Semaphore is that it gets suspended on that point, and thread is freed to do others stuff -- as usual, right?
l

louiscad

06/29/2020, 9:49 PM
There's multiple differences. Semaphore can allow a given number of acquirers that is greater than one for example. The docs are good at explaining each of these.
u

ursus

06/29/2020, 11:16 PM
I know what those two do, I only meant them as a coroutine api, vs their thread equivalent
l

louiscad

06/30/2020, 8:14 AM
Blocking threads is more wasteful, and that's the only thing the non coroutines-friendly version can do.
5 Views