mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
38 lines
801 B
C++
38 lines
801 B
C++
#include <trantor/utils/ConcurrentTaskQueue.h>
|
|
#include "core/log/logger.h"
|
|
#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;
|
|
}
|