Mail GCC project list records show , experimental support for C ++ 20 coroutine has been incorporated into the GCC 10 compiler.
Coroutine (Coroutines) is one of the main functions of C ++ 20, which allows a function and then resume after a pause execution. Examples of the syntax of C ++ coroutine more details and please cppreference.com viewed on. You can see, the definition of official coroutine is:
A coroutine is a function that can suspend execution to be resumed later.
Coroutine function is able to be suspended after recovery.
If the function is defined to achieve any one of the following, it is coroutines:
- Use
co_await
operators suspended until recovery
task<> tcp_echo_server() { char data[ 1024 ]; for (;;) { size_t n = co_await socket.async_read_some(buffer(data)); co_await async_write(socket, buffer(data, n)); } }
- Use keywords to
co_yield
suspend execution and returns a value
generator< int > iota( int n = 0 ) { while ( true ) co_yield n++; }
- Use keywords co_return completes execution and returns a value
lazy< int > f() { co_return 7 ; }
It is understood that the development work coroutine support has been carried out for several months now as the GCC 10 new functions added, is still an experimental implementation.
Since this feature was only added in an early state, and coming in the later stages of the development cycle GCC 10, C ++ 20 coroutine in -std = c ++ 2a is not disclosed in, and now explicitly required to set -fcoroutines flag before use.
For more information about GCC coroutine support status, please see this mailing list post .
In addition, according to GCC support case page for the C ++ standard , GCC will support atomic operations in C ++ (atomic compare-and-exchange) , to complete the work Instant function (immediate functions), get support and other features of C ++ modules of. However, because GCC 10 is already in the fourth stage of the development cycle, so until next year before we can see in this compiler in the GCC 11 complete, it can be put into C ++ 20 support the production environment use.