A simple C implementation of Actor Concurrency Model
Download and put files into your project
Include the header:
#include "actor.h"
Define your actor:
void my_actor_func(actor_t self, void* args)
{
actor_msg_t msg = actor_receive(self); // Receive msg from mailbox
printf("Recv: %ld", msg->msg_type);
fflush(stdout);
// Handle msg
// ...
actor_dispose_msg(msg); // delete msg
return;
}
Spawn your actor:
actor_t my_actor = spawn_actor(my_actor_func, NULL);
Send msg to actor:
actor_msg_t msg = actor_make_msg(MY_MSG_TYPE);
// copy data to msg->payload;
// set reply actor as msg->sender
actor_send(actor_foo, &msg); // send msg