mirror of
https://github.com/tearshark/librf.git
synced 2024-10-04 08:50:31 +08:00
84fe5c4b1a
测试结果表明N:M模型的代码还存在BUG
55 lines
896 B
C++
55 lines
896 B
C++
|
|
#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_vt 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_vt 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();
|
|
}
|