@@ -94,6 +94,7 @@ public open class LockFreedomTestEnvironment(
94
94
}
95
95
96
96
private fun complete () {
97
+ val activeNonPausedThreads: MutableMap <TestThread , Array <StackTraceElement >> = mutableMapOf ()
97
98
val shutdownDeadline = System .currentTimeMillis() + STALL_LIMIT_MS
98
99
try {
99
100
completed = true
@@ -106,21 +107,30 @@ public open class LockFreedomTestEnvironment(
106
107
while (System .currentTimeMillis() < shutdownDeadline) {
107
108
// Check all threads while shutting down:
108
109
// All terminated threads are considered to make progress for the purpose of resuming stalled ones
109
- var hasActiveNonPausedThread = false
110
+ activeNonPausedThreads.clear()
110
111
for (t in threads) {
111
112
when {
112
113
! t.isAlive -> t.makeProgress(getPausedEpoch()) // not alive - makes progress
113
114
t.index.inv () == status.get() -> {} // active, paused -- skip
114
- else -> hasActiveNonPausedThread = true
115
+ else -> {
116
+ val stackTrace = t.stackTrace
117
+ if (t.isAlive) activeNonPausedThreads[t] = stackTrace
118
+ }
115
119
}
116
120
}
117
- if (! hasActiveNonPausedThread ) break
121
+ if (activeNonPausedThreads.isEmpty() ) break
118
122
checkStalled()
119
123
Thread .sleep(SHUTDOWN_CHECK_MS )
120
124
}
125
+ activeNonPausedThreads.forEach { (t, stackTrack) ->
126
+ println (" === $t had failed to shutdown in time" )
127
+ stackTrack.forEach { println (" \t at $it " ) }
128
+ }
121
129
} finally {
122
130
shutdown(shutdownDeadline)
123
131
}
132
+ // if no other exception was throws & we had threads that did not shut down -- still fails
133
+ if (activeNonPausedThreads.isNotEmpty()) error(" Some threads had failed to shutdown in time" )
124
134
}
125
135
126
136
private fun shutdown (shutdownDeadline : Long ) {
0 commit comments