Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

Commit 0895658

Browse files
author
Simon Ninon
committed
[3.5.2] bump tacopie - fixes to address high CPU usage issues.
1 parent 2d12779 commit 0895658

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

examples/redis_subscriber.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@
2121
// SOFTWARE.
2222

2323
#include <cpp_redis/cpp_redis>
24+
#include <tacopie/tacopie>
2425

26+
#include <condition_variable>
2527
#include <iostream>
28+
#include <mutex>
2629
#include <signal.h>
2730

2831
#ifdef _WIN32
2932
#include <Winsock2.h>
3033
#endif /* _WIN32 */
3134

32-
volatile std::atomic<bool> should_exit = ATOMIC_VAR_INIT(false);
35+
std::condition_variable should_exit;
3336

3437
void
3538
sigint_handler(int) {
36-
should_exit = true;
39+
should_exit.notify_all();
3740
}
3841

3942
int
@@ -56,7 +59,7 @@ main(void) {
5659

5760
sub.connect("127.0.0.1", 6379, [](cpp_redis::redis_subscriber&) {
5861
std::cout << "sub disconnected (disconnection handler)" << std::endl;
59-
should_exit = true;
62+
should_exit.notify_all();
6063
});
6164

6265
//! authentication if server-server requires it
@@ -76,7 +79,9 @@ main(void) {
7679
sub.commit();
7780

7881
signal(SIGINT, &sigint_handler);
79-
while (!should_exit) {}
82+
std::mutex mtx;
83+
std::unique_lock<std::mutex> l(mtx);
84+
should_exit.wait(l);
8085

8186
#ifdef _WIN32
8287
WSACleanup();

0 commit comments

Comments
 (0)