Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upIn-type concurrency design #495
Comments
bvssvni
added
draft
information
hard
labels
Jan 11, 2018
bvssvni
removed
the
draft
label
May 21, 2018
bvssvni
closed this
May 24, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bvssvni commentedJan 11, 2018
•
edited
Sender/receiver channels is a common pattern for concurrency programming. Another common programming pattern is the actor model, where entities communicate by ids. Dyon combines these two approaches by treating functions as entities that can communicate with other processes. With other words, you do not have to change your algorithm to support concurrent programming. You can also use this technique for debugging your program, by printing out all input that is sent to a function.
Dyon uses the
inkeyword for creating receiver channels. The sender channel can be any loaded function.Example:
When the
logfunction is called, Dyon checks a flag whether any channels are subscribing. If there is at least one subscriber, Dyon pushes the arguments into an array and sends a copy to each recipient.Here is another example, combining
inandgo:A typical output from the example above:
Notice that the number of received messages varies, because the receiver thread sleeps at different intervals than the sender thread.
You can also receive current objects:
The type of the receiver channel is
in, with an optional inner type e.g.in[[str]]. The inner type created with thein <fn>syntax is an array. For example, if you subscribe to a functionfoo(a: f64, b: f64), then the typein[[f64]]can be used. If the arguments have different types, you can usein[[]],in[[any]]or justin.When a receiver channel runs out of scope, sending new messages fails. Dyon cleans up unused channels by defragmenting the subscriber list and truncating it. This prevents memory leaks when creating and destroying lot of channels.
This also means that the order of receiving events can change:
Notice how
candbchanged order in the example above.When subscribing on a function, all input from all threads is received. To separate different tasks, one must pass in an identifier as an argument to the function.
Design:
intype has an optional inner type e.g.in[[f64]]Rules:
in foowherefoois a loaded function