From 4f742a96dfa53515e838005afc70c3504031857b Mon Sep 17 00:00:00 2001 From: caiyuzheng <290198252@qq.com> Date: Mon, 3 May 2021 02:19:14 +0800 Subject: [PATCH] no message --- test/src/cpp11/CMakeLists.txt | 1 - test/src/cpp11/cpp11_test.cpp | 3 +-- test/src/cpp11/thread_usage.cpp | 23 ++++++++++++++++------- test/src/cpp11/threadpool.cpp | 5 ++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/test/src/cpp11/CMakeLists.txt b/test/src/cpp11/CMakeLists.txt index 03dc733..9b225c8 100644 --- a/test/src/cpp11/CMakeLists.txt +++ b/test/src/cpp11/CMakeLists.txt @@ -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") diff --git a/test/src/cpp11/cpp11_test.cpp b/test/src/cpp11/cpp11_test.cpp index 51af391..40fe11e 100644 --- a/test/src/cpp11/cpp11_test.cpp +++ b/test/src/cpp11/cpp11_test.cpp @@ -4,13 +4,12 @@ #include using namespace std; -#include #include "thread_usage.h" #include "threadpool.h" #include "json.h" - extern "C"{ +#include #include } diff --git a/test/src/cpp11/thread_usage.cpp b/test/src/cpp11/thread_usage.cpp index bdf9c5b..ad1af8a 100644 --- a/test/src/cpp11/thread_usage.cpp +++ b/test/src/cpp11/thread_usage.cpp @@ -148,10 +148,9 @@ class TestTask : public general::Task public: void Run() { - for (int i = 0;i < 100; i ++){ - std::string strValue = "{\"key\":\"value1\",\ - \"array\":[{\"arraykey\":1},{\"arraykey\":2}]}"; - + 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(t2-t1).count(); + std::cout<<"expired is "<(t2-t1).count(); diff --git a/test/src/cpp11/threadpool.cpp b/test/src/cpp11/threadpool.cpp index d6f3be3..724a57b 100644 --- a/test/src/cpp11/threadpool.cpp +++ b/test/src/cpp11/threadpool.cpp @@ -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 lk(mMutex); + while(this->mTasks.size() > 0) + std::this_thread::sleep_for(std::chrono::milliseconds(100)); mStarted = false; mQueueAvaliableCondition.notify_all(); }