mirror of
https://github.com/D-Modem/app.git
synced 2026-11-28 17:38:05 -08:00
Shared io: background() on threads as many as the work, not I/O's 64
Blocking reads held on coroutines' I/O dispatcher (64 threads at most) could leave the next background job waiting for a thread that never came free: PeerLoopbackTest's PIN call hung in the full suite, after the other tests' readers. The peer line, PPP and the transfers each hold a few such threads in the app too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0172Hejd12i4aYikYW9vgpZs
This commit is contained in:
2 files changed
+9
-2
No files matched your search
@@ -608,7 +608,7 @@ object T30 {
|
||||
if (e.post != MPS) break
|
||||
}
|
||||
when {
|
||||
e.dcs != null -> { d = e.dcs!!; continue }
|
||||
e.dcs != null -> { d = e.dcs; continue }
|
||||
e.dcn -> if (pages > 0) return p.copy(phase = "Received") else throw FaxException("the sender hung up")
|
||||
e.post == EOM -> continue@outer
|
||||
e.post == EOP -> {
|
||||
|
||||
@@ -11,9 +11,16 @@ import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
/**
|
||||
* The threads for blocking work: as many as there is work (I/O's 64, the
|
||||
* default, would leave the 65th blocking read waiting for one of the
|
||||
* others to end, which may be never)
|
||||
*/
|
||||
private val blocking = Dispatchers.IO.limitedParallelism(4096)
|
||||
|
||||
/** [f] on a thread of its own for blocking work (the JVM's daemon threads: coroutines' I/O threads) */
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun background(@Suppress("UNUSED_PARAMETER") name: String, f: () -> Unit): Job = GlobalScope.launch(Dispatchers.IO) { f() }
|
||||
fun background(@Suppress("UNUSED_PARAMETER") name: String, f: () -> Unit): Job = GlobalScope.launch(blocking) { f() }
|
||||
|
||||
/** waited for until counted down, once (the JVM's CountDownLatch(1)) */
|
||||
class Latch {
|
||||
|
||||
Reference in new issue
Block a user