2021-06-17 14:43:29 +02:00
|
|
|
#include <trantor/utils/ConcurrentTaskQueue.h>
|
2022-02-10 00:50:19 +01:00
|
|
|
#include "core/log/logger.h"
|
2021-06-17 14:43:29 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <atomic>
|
|
|
|
#include <thread>
|
|
|
|
#include <chrono>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
trantor::ConcurrentTaskQueue queue(5, "concurrT");
|
|
|
|
std::atomic_int sum;
|
|
|
|
sum = 0;
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
queue.runTaskInQueue([&sum]() {
|
|
|
|
LOG_DEBUG << "add sum";
|
|
|
|
for (int i = 0; i < 10000; ++i)
|
|
|
|
{
|
|
|
|
++sum;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
queue.runTaskInQueue([&sum]() {
|
|
|
|
for (int i = 0; i < 20; ++i)
|
|
|
|
{
|
|
|
|
LOG_DEBUG << "sum=" << sum;
|
|
|
|
std::this_thread::sleep_for(100us);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
getc(stdin);
|
|
|
|
LOG_DEBUG << "sum=" << sum;
|
|
|
|
}
|