diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 18:45:06 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-28 18:45:06 +0100 |
commit | 5fd3fe8704374d9ffc77e61d467e13a587d1aff9 (patch) | |
tree | da97f9c160e4bfb55720912227b9a8e789955d38 | |
parent | a1ba5c60d8660751f2765c8ee2cd69453bcbe5f7 (diff) |
Threaded io_service.
-rw-r--r-- | SConstruct | 7 | ||||
-rw-r--r-- | main.cpp | 15 |
2 files changed, 17 insertions, 5 deletions
@@ -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() @@ -1,14 +1,25 @@ -#include <iostream> #include "music.h" #include "httpd.h" +#include <iostream> +#include <vector> + +#include <boost/thread.hpp> + 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<boost::shared_ptr<boost::thread> > threads; + for(std::size_t i = 0; i < 10; i++) { + boost::shared_ptr<boost::thread> 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; } |