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

Blocked thread detection fixes #4195

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions core/jvm/src/main/scala/cats/effect/unsafe/WorkerThread.scala
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,9 @@ private[effect] final class WorkerThread[P <: AnyRef](
if (pool.blockedThreadDetectionEnabled) {
// TODO prefetch pool.workerThread or Thread.State.BLOCKED ?
// TODO check that branch elimination makes it free when off
var otherIdx = random.nextInt(pool.getWorkerThreads.length)
if (otherIdx == idx) {
otherIdx =
(idx + Math.max(1, random.nextInt(pool.getWorkerThreads.length - 1))) % pool
.getWorkerThreads
.length
}
val idx = index
val threadCount = pool.getWorkerThreadCount()
val otherIdx = (idx + random.nextInt(threadCount - 1)) % threadCount
val thread = pool.getWorkerThreads(otherIdx)
val state = thread.getState()
val parked = thread.parked
Expand Down
Loading