Hasty Briefsbeta

Bilingual

Behavior-Oriented Concurrency for Python

6 hours ago
  • #concurrent-programming
  • #python-libraries
  • #resource-synchronization
  • The article uses a cooking example to illustrate how a single-threaded program becomes complex when made concurrent, requiring explicit thread management and locks.
  • It introduces 'cowns' (concurrent-owned variables) and 'behaviors' as a simpler alternative, where cowns ensure exclusive access to resources and behaviors declare dependencies via decorators.
  • The BOC library (bocpy) uses these concepts to rewrite the cooking example without locks, improving readability and scheduling through declarative behavior ordering.
  • The library supports lock-free messaging via Erlang-style send and selective receive, with non-blocking message passing and timeout handling.
  • It includes a built-in Matrix class for efficient numerical operations, safe for sharing across interpreters with zero-copy overhead.
  • A noticeboard feature provides an eventually-consistent global key-value store for lightweight state sharing without dedicated cowns.
  • Performance scaling is near-linear due to parallel sub-interpreters and a lock-free work-stealing scheduler, as demonstrated in benchmarks.