【发布时间】:2016-01-26 12:34:10
【问题描述】:
我正在使用 don't supports the C++ 11 memory model 的 Boost 和 Visual Studio 2013。
启动 Boost 线程时是否有任何内存保证?我在Java Language Specification 17.4.5 中寻找保证:
线程上的 start() 调用发生在已启动线程中的任何操作之前。
就我而言,我想创建一个(非线程安全的)TCP 客户端,然后启动一个接收器线程:
struct Connection {
boost::shared_ptr<TcpClient> client;
};
auto client = boost::shared_ptr<TcpClient>{new TcpClient};
client->setTimeouts(60 * 1000, 60 * 1000);
client->connect(host, port);
auto connection = boost::shared_ptr<Connection>{new Connection};
connection->client = client;
auto receiverThread = boost::shared_ptr<thread>{new thread([&connection]() {
// can I access the client safely?
while (connection->client->isConnected()) {
// do receiving stuff
}
})};
是对client 的更改吗? e.超时,主机和端口,在启动的线程中可见吗?
【问题讨论】:
-
有趣的问题。在实践中,可能是的,但我无法在 boost.js 中找到明确的保证。在 c++11 库中,发布/获取是一种保证。
标签: c++ windows boost boost-thread