libcopp  1.2.1
sample_readme_2.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 // include task header file
4 #include <libcotask/task.h>
5 
7 
8 int main() {
9 #if defined(UTIL_CONFIG_COMPILER_CXX_LAMBDAS) && UTIL_CONFIG_COMPILER_CXX_LAMBDAS
10  // create a task using factory function [with lambda expression]
12  std::cout << "task " << cotask::this_task::get<my_task_t>()->get_id() << " started" << std::endl;
14  std::cout << "task " << cotask::this_task::get<my_task_t>()->get_id() << " resumed" << std::endl;
15  return 0;
16  });
17 
18  std::cout << "task " << task->get_id() << " created" << std::endl;
19  // start a task
20  task->start();
21 
22  std::cout << "task " << task->get_id() << " yield" << std::endl;
23  task->resume();
24  std::cout << "task " << task->get_id() << " stoped, ready to be destroyed." << std::endl;
25 #else
26  std::cerr << "lambda not supported, this sample is not available." << std::endl;
27 #endif
28  return 0;
29 }
int main()
cotask::task my_task_t
static ptr_t create(const Ty &functor, size_t stack_size=0, size_t private_buffer_size=0)
create task with functor
Definition: task.h:162
impl::task_impl * get_task() UTIL_CONFIG_NOEXCEPT
get current running task
Definition: this_task.cpp:15
virtual int yield(void **priv_data)=0