Skip to content

Commit 8a4c1a0

Browse files
committed
Replaced boost::thread with std::thread.
1 parent b3adea8 commit 8a4c1a0

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

boost/network/protocol/http/client/async_impl.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// (See accompanying file LICENSE_1_0.txt or copy at
99
// http://www.boost.org/LICENSE_1_0.txt)
1010

11+
#include <thread>
1112
#include <boost/asio/io_service.hpp>
1213
#include <boost/asio/strand.hpp>
1314
#include <boost/bind.hpp>
1415
#include <boost/make_shared.hpp>
1516
#include <boost/network/protocol/http/traits/connection_policy.hpp>
1617
#include <boost/shared_ptr.hpp>
17-
#include <boost/thread/thread.hpp>
1818

1919
namespace boost {
2020
namespace network {
@@ -62,8 +62,7 @@ struct async_client
6262
connection_base::resolver_strand_.reset(
6363
new boost::asio::io_service::strand(service_));
6464
if (!service)
65-
lifetime_thread_.reset(new boost::thread(
66-
boost::bind(&boost::asio::io_service::run, &service_)));
65+
lifetime_thread_.reset(new std::thread([this] () { service_.run(); }));
6766
}
6867

6968
~async_client() throw() = default;
@@ -93,7 +92,7 @@ struct async_client
9392
boost::asio::io_service& service_;
9493
resolver_type resolver_;
9594
boost::shared_ptr<boost::asio::io_service::work> sentinel_;
96-
boost::shared_ptr<boost::thread> lifetime_thread_;
95+
boost::shared_ptr<std::thread> lifetime_thread_;
9796
optional<string_type> certificate_filename_;
9897
optional<string_type> verify_path_;
9998
optional<string_type> certificate_file_;

libs/network/test/http/server_async_run_stop_concurrency.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#include <thread>
2+
#include <chrono>
13
#include <boost/network/include/http/server.hpp>
2-
#include <boost/thread.hpp>
34

45
namespace http = boost::network::http;
56
namespace util = boost::network::utils;
@@ -23,7 +24,7 @@ int main(int, char*[]) {
2324
#define ASYNC_SERVER_TEST_CONFIG \
2425
options.address("127.0.0.1").port("8007").reuse_address(true)
2526

26-
#define ASYNC_SERVER_SLEEP_TIME boost::posix_time::milliseconds(100)
27+
#define ASYNC_SERVER_SLEEP_TIME std::chrono::milliseconds(100)
2728

2829
// stop from main thread
2930
{
@@ -39,9 +40,9 @@ int main(int, char*[]) {
3940
async_server::options options(async_handler);
4041
async_server server_instance(ASYNC_SERVER_TEST_CONFIG);
4142

42-
boost::thread running_thread(
43+
std::thread running_thread(
4344
boost::bind(&async_server::run, &server_instance));
44-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
45+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
4546

4647
server_instance.stop();
4748
running_thread.join();
@@ -53,13 +54,13 @@ int main(int, char*[]) {
5354
async_server::options options(async_handler);
5455
async_server server_instance(ASYNC_SERVER_TEST_CONFIG);
5556

56-
boost::thread running_thread(
57+
std::thread running_thread(
5758
boost::bind(&async_server::run, &server_instance));
58-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
59+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
5960

60-
boost::thread stopping_thread(
61+
std::thread stopping_thread(
6162
boost::bind(&async_server::stop, &server_instance));
62-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
63+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
6364

6465
stopping_thread.join();
6566
running_thread.join();
@@ -71,21 +72,21 @@ int main(int, char*[]) {
7172
async_server::options options(async_handler);
7273
async_server server_instance(ASYNC_SERVER_TEST_CONFIG);
7374

74-
boost::thread running_thread(
75+
std::thread running_thread(
7576
boost::bind(&async_server::run, &server_instance));
76-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
77+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
7778

78-
boost::thread stopping_thread(
79+
std::thread stopping_thread(
7980
boost::bind(&async_server::stop, &server_instance));
80-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
81+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
8182

82-
boost::thread second_running_thread(
83+
std::thread second_running_thread(
8384
boost::bind(&async_server::run, &server_instance));
84-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
85+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
8586

86-
boost::thread second_stopping_thread(
87+
std::thread second_stopping_thread(
8788
boost::bind(&async_server::stop, &server_instance));
88-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
89+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
8990

9091
stopping_thread.join();
9192
running_thread.join();
@@ -99,17 +100,17 @@ int main(int, char*[]) {
99100
async_server::options options(async_handler);
100101
async_server server_instance(ASYNC_SERVER_TEST_CONFIG);
101102

102-
boost::thread running_thread(
103+
std::thread running_thread(
103104
boost::bind(&async_server::run, &server_instance));
104-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
105+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
105106

106-
boost::thread second_running_thread(
107+
std::thread second_running_thread(
107108
boost::bind(&async_server::run, &server_instance));
108-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
109+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
109110

110-
boost::thread stopping_thread(
111+
std::thread stopping_thread(
111112
boost::bind(&async_server::stop, &server_instance));
112-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
113+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
113114

114115
stopping_thread.join();
115116
running_thread.join();
@@ -122,17 +123,17 @@ int main(int, char*[]) {
122123
async_server::options options(async_handler);
123124
async_server server_instance(ASYNC_SERVER_TEST_CONFIG);
124125

125-
boost::thread running_thread(
126+
std::thread running_thread(
126127
boost::bind(&async_server::run, &server_instance));
127-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
128+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
128129

129-
boost::thread stopping_thread(
130+
std::thread stopping_thread(
130131
boost::bind(&async_server::stop, &server_instance));
131-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
132+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
132133

133-
boost::thread second_stopping_thread(
134+
std::thread second_stopping_thread(
134135
boost::bind(&async_server::stop, &server_instance));
135-
boost::this_thread::sleep(ASYNC_SERVER_SLEEP_TIME);
136+
std::this_thread::sleep_for(ASYNC_SERVER_SLEEP_TIME);
136137

137138
stopping_thread.join();
138139
second_stopping_thread.join();

libs/network/test/uri/uri_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <boost/network/uri/uri.hpp>
1212
#include <boost/network/uri/uri_io.hpp>
1313
#include <boost/range/algorithm/equal.hpp>
14-
#include <boost/scoped_ptr.hpp>
14+
#include <memory>
1515
#include <map>
1616
#include <set>
1717
#include <boost/unordered_set.hpp>
@@ -516,7 +516,7 @@ TEST(URITest, from_file) {
516516

517517
TEST(URITest, issue_104_test) {
518518
// https://github.com/cpp-netlib/cpp-netlib/issues/104
519-
boost::scoped_ptr<uri::uri> instance(new uri::uri("http://www.example.com/"));
519+
std::unique_ptr<uri::uri> instance(new uri::uri("http://www.example.com/"));
520520
uri::uri copy = *instance;
521521
instance.reset();
522522
EXPECT_EQ("http", uri::scheme(copy));

0 commit comments

Comments
 (0)