0

I'm using Xcode 5.0 and boost 1.54. The following code compiles fine using Visual Studio 2008 Sp1, but does not compile in Xcode:

    template <class Rep, class Period>
bool try_lock_for(const boost::chrono::duration<Rep, Period> &_rel_time)
{
    return m_mutex.try_lock_for(_rel_time);
}

I get the error "No member named 'try_lock_until' in 'boost::mutex'" in Xcode.

I am including boost/mutex.hpp and boost/thread.hpp. The Xcode project is setup to use Apple LLVM 5.0 and the GNU99 C++ dialect. I get a similar compile error when I use 'try_lock_until(...)'.

It seems that boost::mutex is defined differently on the two platforms. On Windows the code looks as follows:

namespace detail
{
    typedef ::boost::detail::basic_timed_mutex underlying_mutex;
}

class mutex:
    public ::boost::detail::underlying_mutex
{
    ...
}

So on Windows boost::mutex inherits from timed mutex, but on xcode its just a class that uses pthreads (without support for try_for, etc.).

What is the correct way then to use boost mutex (with try_for) for both Windows and MacOS? Any help would be appreciated.

4

1 回答 1

0

好的,解决了(容易修复)。我用 boost::timed_mutex 替换了 boost::mutex,现在 VS2008 和 Xcode 都在编译,代码没有错误。

于 2013-10-21T07:21:34.617 回答