CAF- C++ actor 模型框架
CAF —— C actor 模型框架,借鉴了 erlang 和 akka的actor思想。使用C现代编程规模实现。特点是:轻量级、分布式、简单、可适应以及无锁。
-和构建:
git clone https://github.com/actor-framework/actor-frameworkcd actor-framework./configuremakemake install [as root, optional]
示例代码:
#include #include #include "caf/all.hpp"using namespace std;using namespace caf;behavior mirror(event_based_actor* self) { // return the (initial) actor behavior return { // a handler for messages containing a single string // that replies with a string [=](const string& what) -> string { // prints "Hello World!" via aout // (thread-safe cout wrapper) aout(self) << what << endl; // terminates this actor // ('become' otherwise loops forever) self->quit(); // reply "!dlroW olleH" return string(what.rbegin(), what.rend()); } };}void hello_world(event_based_actor* self, const actor& buddy) { // send "Hello World!" to our buddy ... self->sync_send(buddy, "Hello World!").then( // ... wait for a response ... [=](const string& what) { // ... and print it aout(self) << what << endl; } );}int main() { // create a new actor that calls 'mirror()' auto mirror_actor = spawn(mirror); // create another actor that calls 'hello_world(mirror_actor)'; spawn(hello_world, mirror_actor); // wait until all other actors we have spawned are done await_all_actors_done(); // run cleanup code before exiting main shutdown();}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~