我需要std::chrono::high_resolution_clock::time_point
字段,我想从一个线程写入并从另一个线程读取。如果我声明它是我的代码编译没有任何错误。std :: atomic <std :: chrono :: high_resolution_clock :: time_point>无法编译
但是,为了使在另一个线程我场可见我围绕着它与std::atomic
这样std::atomic<std::chrono::high_resolution_clock::time_point>
,现在我有以下的编译错误:
/usr/include/c++/4.8/atomic:167:7: error: function ‘std::atomic<_Tp>::atomic() [with _Tp = std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1l, 1000000000l> > >]’ defaulted on its first declaration with an exception-specification that differs from the implicit declaration ‘constexpr std::atomic<std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long int, std::ratio<1l, 1000000000l> > > >::atomic()’
atomic() noexcept = default;
我应该如何申报std::chrono::high_resolution_clock::time_point
场,我从一个线程读写从另一个(以确保“阅读线程”看到最后一个值)?
'atomic'只能与普通可复制类型一起使用,并且据我所知,不能保证'time_point'是可以复制的。 – 2015-03-31 09:05:11
T.C.说的是对的。你可以使用[std :: is_trivial或其他](http://en.cppreference.com/w/cpp/types/is_trivial)测试它... – 2015-03-31 09:08:35