/DeadlocksInCSP

Companion project with code for "Deadlocks in non-hierarchical CSP" blog post

Primary LanguageKotlin

Deadlocks in non-hierarchical CSP

This is a companion project with code for the corresponding blog post.

The original code based on Kotlin Conf 2018 talk "Kotlin Coroutines in Practice" (video, slides).

Code

See the following sources:

Source Description Playground
DownloaderOriginal.kt The original version from presentation that suffers from deadlock. playground
Downloader.go Go version of the same code. playground
DownloaderWithMailbox.kt Does not use select, but actor patter instead. Still deadlocks. playground
DownloaderWithBuffer.kt Same as original but with buffers for both locations and contents channels. Still deadlocks. playground
DownloaderWithUnlimitedBuffer.kt Uses unlimited buffer for contents channel and seems to work. playground
DownloaderWithPriority.kt Gives contents channel priority over references in downloader coroutine. Still deadlocks. playground
DownloaderFixedPriority.kt Fixes the problem by adjusting priority of select in downloader (contents first) and using a buffer for contents channels. playground
DownloaderFixedSelect.kt Fixes the problem by performing locations.send inside select in downloader. playground

Verifier

There is a formal model-checker that takes a simple description of the corresponding communicating final-state machines and exhaustively checks all system states for the presence of deadlocks. It's code is in CFSMVerifier.kt file and there are configuration files for all examples in its directory. The verifier supports plain CFSM using rendezvous channels, has built in capability to represent buffered channels with an addition process, and supports priorities for Kotlin-style select expression using addition "transitional" states.

To use it, run CFSMVerifier with path(s) to the corresponding .cfsm configuration files.