libPhenomC 語言并發(fā)編程框架
libPhenom 是 Facebook 發(fā)布的一個高性能的C語言并發(fā)編程框架,支持事件驅(qū)動,支持多線程,還提供了內(nèi)存管理和常用數(shù)據(jù)結(jié)構(gòu),甚至是json處理。
示例代碼:
#include "phenom/defs.h"
#include "phenom/job.h"
#include "phenom/log.h"
#include "phenom/sysutil.h"
int main(int argc, char **argv)
{
// Must be called prior to calling any other phenom functions
ph_library_init();
// Optional config file for tuning internals
ph_config_load_config_file("/path/to/my/config.json");
// Enable the non-blocking IO manager
ph_nbio_init(0);
// Do stuff here to register client/server stuff.
// This enables a very simple request/response console
// that allows you to run diagnostic commands:
// `echo memory | nc -UC /tmp/phenom-debug-console`
// The code behind this is in
// https://github.com/facebook/libphenom/blob/master/corelib/debug_console.c
ph_debug_console_start("/tmp/phenom-debug-console");
// Run
ph_sched_run();
return 0;
}評論
圖片
表情
