123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
-
- #include <chrono>
- #include <iostream>
- #include <string>
- #include <conio.h>
- #include <thread>
- #include <deque>
-
- #include "librf.h"
-
- using namespace resumef;
-
- mutex_t g_lock;
- std::deque<size_t> g_queue;
-
- future_t<> test_mutex_pop(size_t idx)
- {
- using namespace std::chrono;
-
- for (size_t i = 0; i < 10; ++i)
- {
- co_await resumf_guard_lock(g_lock);
-
- if (g_queue.size() > 0)
- {
- size_t val = g_queue.front();
- g_queue.pop_front();
-
- std::cout << val << " on " << idx << std::endl;
- }
- co_await sleep_for(500ms);
- }
- }
-
- future_t<> test_mutex_push()
- {
- using namespace std::chrono;
-
- for (size_t i = 0; i < 10; ++i)
- {
- co_await resumf_guard_lock(g_lock);
- g_queue.push_back(i);
-
- co_await sleep_for(500ms);
- }
- }
-
- void resumable_main_mutex()
- {
- go test_mutex_push();
- go test_mutex_pop(1);
-
- this_scheduler()->run_until_notask();
- }
|