Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the sample code does not reproduce the problem #198

Closed
Vixb1122 opened this issue Jan 5, 2018 · 1 comment
Closed

Using the sample code does not reproduce the problem #198

Vixb1122 opened this issue Jan 5, 2018 · 1 comment

Comments

@Vixb1122
Copy link
Contributor

Vixb1122 commented Jan 5, 2018

See: https:/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md#the-problem

Note: if you have an old system with 2 or fewer CPUs, then you will consistently see 1000000, because CommonPool is running in only one thread in this case. To reproduce the problem you'll need to make the following change:

val mtContext = newFixedThreadPoolContext(2, "mtPool") // explicitly define context with two threads
var counter = 0

fun main(args: Array<String>) = runBlocking<Unit> {
    massiveRun(mtContext) { // use it instead of CommonPool in this sample and below 
        counter++
    }
    println("Counter = $counter")
}

I will not consitently see 1000000.

outputs:

Completed 1000000 actions in 25 ms
Counter = 892791
Completed 1000000 actions in 26 ms
Counter = 862276
Completed 1000000 actions in 29 ms
Counter = 881049
@elizarov
Copy link
Contributor

It will be fixed when we implement our own implementation for DefaultDispatcher instead of CommonPool.

elizarov added a commit that referenced this issue Sep 28, 2018
* Documentation and guide are updated correspondingly
* "DefaultDispatcher" is used as a public name of the default impl
* Implementation is integrated with virtual time-source
* Shutdown sequence is reimplemented in a safe way for tests,
  makes "close" safe to use on custom instances.
* "close" on DefaultDispatcher throws exception just in case
* -Dkotlinx.coroutines.scheduler=off can be used to switch back to
  CommonPool

Fixes #198
elizarov added a commit that referenced this issue Sep 28, 2018
* Documentation and guide are updated correspondingly
* "DefaultDispatcher" is used as a public name of the default impl
* Implementation is integrated with virtual time-source
* Shutdown sequence is reimplemented in a safe way for tests,
  makes "close" safe to use on custom instances.
* "close" on DefaultDispatcher throws exception just in case
* -Dkotlinx.coroutines.scheduler=off can be used to switch back to
  CommonPool

Fixes #198
elizarov added a commit that referenced this issue Sep 28, 2018
* Documentation and guide are updated correspondingly
* "DefaultDispatcher" is used as a public name of the default impl
* Implementation is integrated with virtual time-source
* Shutdown sequence is reimplemented in a safe way for tests,
  makes "close" safe to use on custom instances.
* "close" on DefaultDispatcher throws exception just in case
* -Dkotlinx.coroutines.scheduler=off can be used to switch back to
  CommonPool

Fixes #198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants