From 5fd3fe8704374d9ffc77e61d467e13a587d1aff9 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 28 Dec 2010 18:45:06 +0100 Subject: Threaded io_service. --- SConstruct | 7 ++++--- main.cpp | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index 75371ae..94a14d5 100644 --- a/SConstruct +++ b/SConstruct @@ -3,9 +3,10 @@ AddOption('--release', action = 'store_true') env = Environment(CPPPATH = ['.'], CCFLAGS = ['-pthread'], LINKFLAGS = ['-pthread']) conf = Configure(env) -conf.CheckLib('boost_system') -conf.CheckLib('boost_filesystem') -conf.CheckLib('boost_regex') +conf.CheckLib('boost_system-mt') +conf.CheckLib('boost_filesystem-mt') +conf.CheckLib('boost_regex-mt') +conf.CheckLib('boost_thread-mt') conf.CheckLib('mp3lame') env = conf.Finish() diff --git a/main.cpp b/main.cpp index bb165a1..3827607 100644 --- a/main.cpp +++ b/main.cpp @@ -1,14 +1,25 @@ -#include #include "music.h" #include "httpd.h" +#include +#include + +#include + int main(int argc, char **argv) { try { music::init(argv[1]); boost::asio::io_service io_service; HTTPServer httpd(io_service); - io_service.run(); + std::vector > threads; + for(std::size_t i = 0; i < 10; i++) { + boost::shared_ptr thread(new boost::thread(boost::bind(&boost::asio::io_service::run, &io_service))); + threads.push_back(thread); + } + for(std::size_t i = 0; i < 10; i++) { + threads[i]->join(); + } } catch(std::exception& e) { std::cerr << e.what() << std::endl; } -- cgit v1.2.3