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.

Arno Duvenhage
  • 1,910
  • 17
  • 36
  • 1
    But boost::mutex really doesn't have these functions in its interface. Perhaps you use some `typedef`, which resolves to `boost::mutex` on one platform, but to `boost::timed_mutex` (or so) on another platform? Could you prepare an sscce? – Igor R. Oct 15 '13 at 18:44
  • Yes, I checked and that is correct. On Windows and MacOS the boost mutex is defined differently (I will edit the question accordingly, since I still can't compile with Xcode). – Arno Duvenhage Oct 21 '13 at 06:42

1 Answers1

0

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.

Arno Duvenhage
  • 1,910
  • 17
  • 36
  • Yes, if you need `TimedLockable` concept, you have to use one of its models (like `timed_mutex`). It turns out that the Windows version of `mutex` implements this concept as well, but this is merely an implementation detail - one shouldn't rely on that. – Igor R. Oct 21 '13 at 11:43