基于C++ Coroutines提案 ‘Stackless Resumable Functions’编写的协程库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_memory_leak.cpp 949B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <chrono>
  2. #include <iostream>
  3. #include <string>
  4. #include <thread>
  5. #include "librf/librf.h"
  6. using namespace librf;
  7. using namespace std::chrono;
  8. void test_memory_leak_event_wait_for()
  9. {
  10. go[]()->future_t<void>
  11. {
  12. event_t e;
  13. for (;;)
  14. {
  15. bool val = co_await e.wait_for(1ms);
  16. assert(val == false);
  17. co_await yield();
  18. }
  19. };
  20. for (;;)
  21. {
  22. auto have = this_scheduler()->run_one_batch();
  23. if (!have) {
  24. std::this_thread::sleep_for(1ms);
  25. }
  26. }
  27. }
  28. void test_memory_leak_event_wait_all_for()
  29. {
  30. go[]()->future_t<void>
  31. {
  32. event_t e[4];
  33. for (;;)
  34. {
  35. bool val = co_await event_t::wait_all_for(1ms, e);
  36. assert(val == false);
  37. co_await yield();
  38. }
  39. };
  40. for (;;)
  41. {
  42. auto have = this_scheduler()->run_one_batch();
  43. if (!have) {
  44. std::this_thread::sleep_for(1ms);
  45. }
  46. }
  47. }
  48. #if LIBRF_TUTORIAL_STAND_ALONE
  49. int main()
  50. {
  51. //test_memory_leak_event_wait_for();
  52. test_memory_leak_event_wait_all_for();
  53. return 0;
  54. }
  55. #endif