From 0bf2391d4a908b48254ea844b88176201b5a5d03 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 27 Jan 2014 13:57:52 +0200 Subject: [PATCH] fix test --- build/gcc/makefile | 6 +++--- src/test.cpp | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/build/gcc/makefile b/build/gcc/makefile index c2ce3148..1cd01236 100644 --- a/build/gcc/makefile +++ b/build/gcc/makefile @@ -7,9 +7,9 @@ OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES)) CXX = g++ -CXXFLAGS = -Wall -std=c++11 -pthread -I../../include -CXX_RELEASE_FLAGS = -O3 -flto -CXX_DEBUG_FLAGS= -g +CXXFLAGS = -march=native -Wall -std=c++11 -pthread -I../../include +CXX_RELEASE_FLAGS = -O2 -flto +CXX_DEBUG_FLAGS= -g -ggdb OUTLIB_RELEASE = libc11log.a OUTLIB_DEBUG = libc11log-debug.a diff --git a/src/test.cpp b/src/test.cpp index 4ff5412b..2e640c7c 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -26,27 +26,37 @@ int main(int argc, char* argv[]) logger.add_sink(async); std::atomic counter { 0 }; - auto counter_ptr = &counter; - std::cout << "Starting " << nthreads << " threads.." << std::endl; + auto counter_ptr = &counter; + std::atomic active{true}; + auto active_ptr = &active; + + std::vector threads; + std::cout << "Starting " << nthreads << " threads for 3 seconds.." << std::endl; for (int i = 0; i < nthreads; i++) { - new std::thread([&logger, counter_ptr]() { - while (true) + auto t = new std::thread([&logger, counter_ptr, active_ptr]() { + while (*active_ptr) { logger.info() << "Hello from thread " << std::this_thread::get_id() << "\tcounter: " << counter_ptr->load(); (*counter_ptr)++; - } + } }); + threads.push_back(t); } + int seconds = 0; - while (seconds++ < 5) + while (seconds++ < 3) { counter = 0; std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << "Counter = " << utils::format(counter.load()) << std::endl; } - async->shutdown(std::chrono::seconds(10)); + active = false; + for(auto t:threads) + t->join(); + async->shutdown(std::chrono::seconds(1)); + return 0; }