Вопрос

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.

Это было полезно?

Решение

ok, solved it (easy fix). I replaced boost::mutex with boost::timed_mutex and now both VS2008 and Xcode are compiling without errors on the code.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top