-
Notifications
You must be signed in to change notification settings - Fork 0
/
sizes.cpp
55 lines (50 loc) · 1.88 KB
/
sizes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2024 Dr. Colin Hirsch
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
#include <cassert>
#include <iostream>
#include "mini_coro_plus.hpp"
#include "mini_coro_plus.ipp"
int sum;
void function()
{
mcp::control().yield();
char a[ 128 ];
mcp::control().yield();
for( std::size_t i = 0; i < sizeof( a ); ++i ) {
sum += a[ i ];
}
mcp::control().yield();
char b[ 1024 ];
mcp::control().yield();
for( std::size_t i = 0; i < sizeof( b ); ++i ) {
sum += b[ i ];
}
mcp::control().yield();
}
int main()
{
mcp::coroutine coro( function );
assert( coro.state() == mcp::state::STARTING );
std::cout << "stack size: " << coro.stack_size() << " used: " << coro.stack_used() << std::endl;
coro.resume();
assert( coro.state() == mcp::state::SLEEPING );
std::cout << "stack size: " << coro.stack_size() << " used: " << coro.stack_used() << std::endl;
coro.resume();
assert( coro.state() == mcp::state::SLEEPING );
std::cout << "stack size: " << coro.stack_size() << " used: " << coro.stack_used() << std::endl;
coro.resume();
assert( coro.state() == mcp::state::SLEEPING );
std::cout << "stack size: " << coro.stack_size() << " used: " << coro.stack_used() << std::endl;
coro.resume();
assert( coro.state() == mcp::state::SLEEPING );
std::cout << "stack size: " << coro.stack_size() << " used: " << coro.stack_used() << std::endl;
coro.resume();
assert( coro.state() == mcp::state::SLEEPING );
std::cout << "stack size: " << coro.stack_size() << " used: " << coro.stack_used() << std::endl;
coro.resume();
assert( coro.state() == mcp::state::COMPLETED );
std::cout << "stack size: " << coro.stack_size() << " used: " << coro.stack_used() << std::endl;
std::cout << "sum " << sum << std::endl;
return 0;
}