Implementation of the actor model for concurrent programming.
The actors send messages to each other and respond to them based on their roles.
A role is a list of functions assigned to message types.
Each actor has their own message queue and internal state.
Each actor supports three predefined message types: MSG_SPAWN
, MSG_GODIE
, MSG_HELLO
You can build and test the library this way:
mkdir build && cd build
cmake ../src
make
make test
Two sample programs using this library are included:
matrix.c
Program recieves two numbersh
andw
from stdin, each on a separate line. These numbers represent the height and width of the input matrix. Next,h*w
lines are read of the formx t
, wherex
is the next value in a matrix, andt
is the time to wait for that value (in milliseconds). The program createsw
actors, each responsible for a different column. The next step is to sum the values in each row, with the appropriate waiting time and order from left to right. Finally, the program prints out the result for each row. Example:
./matrix
2
3
1 2
1 5
12 4
23 9
3 11
7 2
results in (with appropriate waiting time):
14
33
factorial.c
Computes the factorial of a given numbern
in stdin. Each of then
actors receives the current result, multiplies it by its value and passes it on. Result is printed to stdout.
Sample usage:echo 5 | ./factorial
results in120
.