Pony
Pony is an open-source, actor-model language for high-performance, safe concurrency, created by Sylvan Clebsch. Its compiler uses reference capabilities to prove that a program has no data races and no lock-based deadlocks, before it ever runs.
Paradigm: Concurrent and Actor Programming
What Makes Pony Special
- Actors and behaviours. An
actorhas private state and behaviours (be), asynchronous methods that other actors call by sending a message. - Reference capabilities. Every reference has a capability such as
iso,val,refortagthat says who may read or write the object. The compiler enforces them. - No data races by construction. Mutable data can be sent to another actor only when the sender gives up all access to it (
iso) or the data is immutable (val). - No locks, no blocking. Actors never block waiting for a message. Each actor processes one behaviour at a time.
- Per-actor garbage collection. Each actor collects its own heap, so there are no global pauses, and performance is predictable.
Example: An actor that counts
actor Counter
var _count: U32 = 0
be increment() =>
_count = _count + 1
be report(out: OutStream) =>
out.print("count: " + _count.string())
actor Main
new create(env: Env) =>
let c = Counter.create()
c.increment()
c.increment()
c.report(env.out)
How It Works
Counterkeeps a private field_count. Only its own behaviours can touch it, so no lock is needed.bedeclares a behaviour. Callingc.increment()does not run it directly: it puts a message in the actor's queue and returns immediately.- Messages from one actor to another arrive in order, so the two increments run before
report, and the program printscount: 2. - An actor reference always has the capability
tag: you can send messages to it, but you cannot read or write its fields from outside.
History and Where It Is Used
Pony is used in research and for low-latency systems such as financial trading experiments (Wallaroo Labs used it for stream processing). It is a small community, but a valuable way to see how a type system can guarantee safe concurrency. The Pony tutorial explains capabilities with many diagrams.
Learn More
- Pony language
- Pony (Wikipedia)
- Back to Concurrent and Actor Programming or the PGP roadmap.