no message

master
caiyuzheng 2021-05-03 02:19:14 +08:00
parent 662860689d
commit 4f742a96df
4 changed files with 19 additions and 13 deletions

View File

@ -10,5 +10,4 @@ link_directories("./third/jsoncpp/lib/")
link_libraries(jsoncpp)
add_executable(cpp11 ${SOURCE} )
include_directories("./third/jsoncpp/include/pkgsrc/include/json")
# target_link_libraries(cpp11 "jsoncpp")

View File

@ -4,13 +4,12 @@
#include<iostream>
using namespace std;
#include<stdio.h>
#include "thread_usage.h"
#include "threadpool.h"
#include "json.h"
extern "C"{
#include<stdio.h>
#include <time.h>
}

View File

@ -148,10 +148,9 @@ class TestTask : public general::Task
public:
void Run()
{
for (int i = 0;i < 100; i ++){
auto t1 = std::chrono::steady_clock::now();
std::string strValue = "{\"key\":\"value1\",\
\"array\":[{\"arraykey\":1},{\"arraykey\":2}]}";
Json::Reader reader;
Json::Reader reader1;
Json::Reader reader2;
@ -160,10 +159,15 @@ public:
Json::Value root1;
Json::Value root2;
for (int i = 0;i < ; i ++){
reader.parse(strValue, root);
reader1.parse(strValue, root1);
reader2.parse(strValue, root2);
}
auto t2 = std::chrono::steady_clock::now();
double dr_ms = std::chrono::duration<double,std::milli>(t2-t1).count();
std::cout<<"expired is "<<dr_ms<<std::endl;
}
};
// 42973.6
@ -172,12 +176,17 @@ int TestThreadPool()
{
//run code
TestTask *t = new TestTask;
general::ThreadPool pool(1);
pool.Start();
general::ThreadPool pool(3);
auto t1 = std::chrono::steady_clock::now();
for(int i = 0;i < 2000;i++){
for(int i = 0;i < 10;i++){
pool.AddTask(t);
}
pool.Start();
for(int i = 0;i < 20;i++){
pool.AddTask(t);
}
pool.StopAll();
auto t2 = std::chrono::steady_clock::now();
double dr_ms = std::chrono::duration<double,std::milli>(t2-t1).count();

View File

@ -54,7 +54,6 @@ namespace general{
{
mQueueAvaliableCondition.wait(lk);
}
if(!mStarted){
return nullptr;
}
@ -97,8 +96,8 @@ namespace general{
void CThreadPool::StopAll()
{
{
while(this->mTasks.size() > 0) ;
std::lock_guard<std::mutex> lk(mMutex);
while(this->mTasks.size() > 0)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
mStarted = false;
mQueueAvaliableCondition.notify_all();
}