Deadlocks in non-hierarchical CSP

The stage

while (true) {
select<Unit> {
references.onReceive { ref -> // (1)
val
loc = ref.resolveLocation()
...
locations.send(loc) // (2)
}
contents.onReceive { (loc, content) -> ... } // (3)
}
}
for (loc in locations) {                             // (4)
val content = downloadContent(loc)
contents.send(LocContent(loc, content)) // (5)
}

Deadlock demo

Solutions that do not work

for (msg in mailbox) {
when (msg) {
is Reference -> ...
is LocContent -> ...
}
}

Unlimited-capacity channels

Solutions that do work

select<Unit> {
contents.onReceive { ... }
references.onReceive {
...

locations.send(loc) // (2)
}
}
val contents = Channel<LocContent>(1)

Conclusion

Credits

UPDATE: The future roadmap

Footnotes

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Roman Elizarov

Roman Elizarov

Project Lead for the Kotlin Programming Language @JetBrains