Pergunta

I have an application developed with VS2010, which uses Boost.Thread 1.48.

Currently I'm trying to port the application to Linux (running on Debian 7).

When I try to compile it with GCC 4.6 or clang, I get the following error

error: ‘class boost::mutex’ has no member named ‘timed_lock’

Are there any preprocessor definitions or compiler flags I have to set?

EDIT: OK, I have found the issue. I used the following:

myfile.h:

boost::mutex myMutex;

myfile.cpp

if(myMutex.timed_lock(boost::posix_time::millisec(10000)))
{
    // Do stuff
    // ...
    // ...

    myMutex.unlock();
    return true;
}

myMutex.unlock();
return false;

This works fine with VS2008/2010. Under Linux I had to change the header to:

boost::timed_mutex myMutex;

I'm still not quite sure, what's the reason.

Foi útil?

Solução

In windows platform boost::mutex and boost::timed_mutex share the same implementation. This is an implementation detail.

You should use boost::time_mutex if you want to use timed_lock() as Boost.Thread documents.

http://www.boost.org/doc/libs/1_55_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_types.timed_mutex

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top