【问题标题】:Boost 1.48.0 upgrade_to_unique_lock on Linux: Has something changed since 1.47 or I do something wrong?Linux 上的 Boost 1.48.0 upgrade_to_unique_lock:自 1.47 以来发生了什么变化还是我做错了什么?
【发布时间】:2011-11-24 16:12:26
【问题描述】:

我有一个小的 cpp sourceh source 文件,其中包含一些类。它使用shared mutexes and shared locks。它在 windows 上编译,使用 boost 1.48.0 没有错误。它还在 linux 上编译(之前使用 boost 1.47)。但是现在有这样的代码:

 boost::shared_mutex mut_;
 //...
 boost::upgrade_lock<boost::shared_mutex> lock(mut_);
 boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);

导致奇怪的错误:

==== Building cf-fs (debug) ====
Creating bin/obj/Debug/cf-fs
fs_concurrent_queued_map.cpp
fs_map.cpp
In file included from ../../src/cf-util/http_utils_inl.h:1,
                 from ../../src/cf-util/http_utils.h:104,
                 from ../../src/cf-fs/fs_map.h:13,
                 from ../../src/cf-fs/fs_map.cpp:1:
../../src/cf-util/http_utils.h:105:8: warning: extra tokens at end of #endif directive
In file included from ../../src/cf-fs/fs_map.h:13,
                 from ../../src/cf-fs/fs_map.cpp:1:
../../src/cf-util/http_utils.h:105:8: warning: extra tokens at end of #endif directive
In file included from ../../../boost_libraries/install-dir/include/boost/thread/pthread/mutex.hpp:12,
                 from ../../../boost_libraries/install-dir/include/boost/thread/mutex.hpp:16,
                 from ../../../boost_libraries/install-dir/include/boost/thread/pthread/thread_data.hpp:12,
                 from ../../../boost_libraries/install-dir/include/boost/thread/thread.hpp:17,
                 from ../../../boost_libraries/install-dir/include/boost/thread.hpp:13,
                 from ../../src/cf-fs/fs_map.h:10,
                 from ../../src/cf-fs/fs_map.cpp:1:
../../../boost_libraries/install-dir/include/boost/thread/locks.hpp: In constructor ‘boost::upgrade_to_unique_lock<Mutex>::upgrade_to_unique_lock(boost::upgrade_lock<Mutex>&) [with Mutex = boost::shared_mutex]’:
../../src/cf-fs/fs_map.cpp:33:   instantiated from here
../../../boost_libraries/install-dir/include/boost/thread/locks.hpp:926: error: call of overloaded ‘move(boost::upgrade_lock<boost::shared_mutex>&)’ is ambiguous
../../../boost_libraries/install-dir/include/boost/thread/detail/move.hpp:44: note: candidates are: typename boost::enable_if<boost::is_convertible<T&, boost::detail::thread_move_t<T> >, boost::detail::thread_move_t<T> >::type boost::move(T&) [with T = boost::upgrade_lock<boost::shared_mutex>]
../../../boost_libraries/install-dir/include/boost/move/move.hpp:294: note:                 typename boost::move_detail::disable_if<boost::has_move_emulation_enabled<T>, T&>::type boost::move(T&) [with T = boost::upgrade_lock<boost::shared_mutex>]
../../../boost_libraries/install-dir/include/boost/thread/locks.hpp: In destructor ‘boost::upgrade_to_unique_lock<Mutex>::~upgrade_to_unique_lock() [with Mutex = boost::shared_mutex]’:
../../src/cf-fs/fs_map.cpp:33:   instantiated from here
../../../boost_libraries/install-dir/include/boost/thread/locks.hpp:932: error: call of overloaded ‘move(boost::unique_lock<boost::shared_mutex>&)’ is ambiguous
../../../boost_libraries/install-dir/include/boost/thread/detail/move.hpp:44: note: candidates are: typename boost::enable_if<boost::is_convertible<T&, boost::detail::thread_move_t<T> >, boost::detail::thread_move_t<T> >::type boost::move(T&) [with T = boost::unique_lock<boost::shared_mutex>]
../../../boost_libraries/install-dir/include/boost/move/move.hpp:294: note:                 typename boost::move_detail::disable_if<boost::has_move_emulation_enabled<T>, T&>::type boost::move(T&) [with T = boost::unique_lock<boost::shared_mutex>]
make[1]: *** [bin/obj/Debug/cf-fs/fs_map.o] Ошибка 1
make: *** [cf-fs] Ошибка 2

我的代码中是否存在无法编译的错误以及如何修复或绕过它?

【问题讨论】:

  • 我认为是这个问题:svn.boost.org/trac/boost/ticket/6141
  • 是的。看起来是的。任何人都可以提供任何方法来解决它(而不是摆脱或共享锁)?
  • 您必须进入 Boost 源并禁用 Boost.Move 或修复该票证中描述的错误。

标签: c++ boost locking boost-thread


【解决方案1】:
--- a/locks.hpp 2011-12-05 12:26:11.650309054 +0400
+++ b/locks.hpp 2011-12-05 12:27:25.905311415 +0400
@@ -923,13 +923,13 @@
         upgrade_to_unique_lock& operator=(upgrade_to_unique_lock&);
     public:
         explicit upgrade_to_unique_lock(upgrade_lock<Mutex>& m_):
-            source(&m_),exclusive(move(*source))
+            source(&m_),exclusive(move(detail::thread_move_t<upgrade_lock<Mutex> >(*source)))
         {}
         ~upgrade_to_unique_lock()
         {
             if(source)
             {
-                *source=move(exclusive);
+                *source=move(detail::thread_move_t<unique_lock<Mutex> >(exclusive));
             }
         }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-14
    • 2017-08-23
    • 2011-03-28
    相关资源
    最近更新 更多