基于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 977B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. (void)val;
  17. assert(val == false);
  18. co_await yield();
  19. }
  20. };
  21. for (;;)
  22. {
  23. auto have = this_scheduler()->run_one_batch();
  24. if (!have) {
  25. std::this_thread::sleep_for(1ms);
  26. }
  27. }
  28. }
  29. void test_memory_leak_event_wait_all_for()
  30. {
  31. go[]()->future_t<void>
  32. {
  33. event_t e[4];
  34. for (;;)
  35. {
  36. bool val = co_await event_t::wait_all_for(1ms, e);
  37. (void)val;
  38. assert(val == false);
  39. co_await yield();
  40. }
  41. };
  42. for (;;)
  43. {
  44. auto have = this_scheduler()->run_one_batch();
  45. if (!have) {
  46. std::this_thread::sleep_for(1ms);
  47. }
  48. }
  49. }
  50. #if LIBRF_TUTORIAL_STAND_ALONE
  51. int main()
  52. {
  53. //test_memory_leak_event_wait_for();
  54. test_memory_leak_event_wait_all_for();
  55. return 0;
  56. }
  57. #endif