From 4d938d149e782a6e2fed668eec4e1a023df9f35c Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期一, 26 十二月 2022 10:15:37 +0800 Subject: [PATCH] optimize cpu --- main.cpp | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 35b6ddf..8811cf0 100644 --- a/main.cpp +++ b/main.cpp @@ -41,7 +41,7 @@ int ret = bus_client_publish(handle, i.data(), i.size(), msg.data(), msg.size()); printf("======>> bus_client_pubmsg [%s] ret %d\n", msg.c_str(), ret); - this_thread::sleep_for(chrono::seconds{2}); + this_thread::sleep_for(chrono::seconds{1}); } } } @@ -61,6 +61,7 @@ while (true) { auto msg = bus_client_get_submsg(handle); printf("SUB msg topic [%s] data [%s]\n", msg->topic, msg->msg); + free_submsg(msg); } bus_client_free(handle); @@ -76,10 +77,10 @@ creg_free(reg); size_t count = 0; - string base_msg("test_request=="); + string base_msg("test_request==request message -> msg-"); this_thread::sleep_for(chrono::seconds(3)); while (true) { - auto msg = base_msg + "request message -> msg-"+to_string(count++); + auto msg = base_msg + to_string(count++); auto reqmsg = make_req_msg(topic, topicl, msg.data(), msg.size()); crepmsg* repmsg = NULL; if (bus_client_request(handle, reqmsg, &repmsg)){ @@ -118,7 +119,7 @@ printf("REPREQ msg [%s] \n", msg->msg); free_reqmsg(msg); - this_thread::sleep_for(chrono::seconds{2}); + // this_thread::sleep_for(chrono::seconds{2}); } } @@ -137,4 +138,4 @@ reply(rrtopic); return 0; -} \ No newline at end of file +} -- Gitblit v1.8.0