50int main(
int argc,
char *argv[]) {
51#ifdef LIBCOPP_MACRO_SYS_POSIX
52 puts(
"###################### context coroutine (stack using default allocator[mmap]) ###################");
53#elif defined(LIBCOPP_MACRO_SYS_WIN)
54 puts(
"###################### context coroutine (stack using default allocator[VirtualAlloc]) ###################");
56 puts(
"###################### context coroutine (stack using default allocator ###################");
58 printf(
"########## Cmd:");
59 for (
int i = 0; i < argc; ++i) {
60 printf(
" %s", argv[i]);
72 size_t stack_size = 16 * 1024;
74 stack_size =
static_cast<size_t>(atoi(argv[3]) * 1024);
77 time_t begin_time = time(
nullptr);
83 time_t end_time = time(
nullptr);
85 printf(
"allocate %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
max_coroutine_number,
86 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),
94 fprintf(stderr,
"coroutine create failed, the real number is %d\n", i);
95 fprintf(stderr,
"maybe sysconf [vm.max_map_count] extended?\n");
101 end_time = time(
nullptr);
103 printf(
"create %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
max_coroutine_number,
104 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),
107 begin_time = end_time;
108 begin_clock = end_clock;
116 bool continue_flag =
true;
117 long long real_switch_times =
static_cast<long long>(0);
119 while (continue_flag) {
120 continue_flag =
false;
122 if (
false ==
co_arr[i]->is_finished()) {
123 continue_flag =
true;
130 end_time = time(
nullptr);
132 printf(
"switch %d coroutine contest %lld times, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
136 begin_time = end_time;
137 begin_clock = end_clock;
141 end_time = time(
nullptr);
143 printf(
"remove %d coroutine, cost time: %d s, clock time: %d ms, avg: %lld ns\n",
max_coroutine_number,
144 static_cast<int>(end_time - begin_time),
CALC_MS_CLOCK(end_clock - begin_clock),
static ptr_type create(callback_type &&runner, allocator_type &alloc, size_t stack_sz=0, size_t private_buffer_size=0, size_t coroutine_size=0) LIBCOPP_MACRO_NOEXCEPT
create and init coroutine with specify runner and specify stack size