acl/lib_fiber/samples/fiber_cpp/main.cpp

57 lines
850 B
C++

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
class myfiber : public acl::fiber
{
public:
myfiber(void) {}
~myfiber(void) {}
protected:
// @override
void run(void)
{
printf("fiber-%d-%d running\r\n", get_id(), acl::fiber::self());
delete this;
}
};
static void usage(const char* procname)
{
printf("usage: %s -h [help] -n fibers_count\r\n", procname);
}
int main(int argc, char *argv[])
{
int ch, n = 10;
acl::acl_cpp_init();
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "hn:")) > 0)
{
switch (ch)
{
case 'h':
usage(argv[0]);
return 0;
case 'n':
n = atoi(optarg);
break;
default:
break;
}
}
for (int i = 0; i < n; i++)
{
acl::fiber* f = new myfiber();
f->start();
}
acl::fiber::schedule();
return 0;
}