首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >boost::interprocess::interprocess_condition::timed_wait()编译器错误

boost::interprocess::interprocess_condition::timed_wait()编译器错误
EN

Stack Overflow用户
提问于 2020-07-27 22:21:17
回答 1查看 229关注 0票数 0

我正在尝试在共享内存中创建一些对象(这将是一个未来的问题),但目前我已经得到了一个编译器错误(使用g++ 4.8.5在RHEL7.8上使用boost 1.53.0 ),但我无法弄清楚。

Event.h

代码语言:javascript
复制
#include <boost/interprocess/sync/interprocess_condition.hpp>
#include <boost/interprocess/sync/interprocess_mutex.hpp>

class Event
{
public:
   Event (std::string name, boost::interprocess::managed_shared_memory shmem);

   int SetEvent ();
   int ResetEvent ();

   int WaitForEvent (int64_t milliseconds = -1);

private:
   typedef boost::interprocess::allocator<boost::interprocess::basic_string<char>, std::char_traits<char> >, boost::interprocess::managed_shared_memory::segment_manager> StringAllocator;
   typedef boost::interprocess::basic_string<char, std::char_traits<char>, StringAllocator> ShareableString;

   typedef boost::interprocess::allocator<boost::interprocess::deque<pwfmo_info_t_>, boost::interprocess::managed_shared_memory::segment_manager> DequeAllocator;
   typedef boost::interprocess::deque<pwfmo_info_t_, DequeAllocator> SharedDeque;

   boost::interprocess::interprocess_mutex Mutex;
   boost::interprocess::interprocess_condition Condition;
   ShareableString mName;
   bool State;
   ShareableDeque  mRegisteredWaits;
}

Event.cpp

代码语言:javascript
复制
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>

int Event::WaitForEvent(int64_t milliseconds)
{
    Mutex.lock();
       
    if(!State)
    {   
        boost::posix_time::ptime time;
        if (milliseconds == -1)
        {
            time = boost::date_time::microsec_clock<boost::posix_time::ptime>::local_time();
            time += boost::posix_time::millisec (milliseconds);
        }

        do
        {
            boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> lock (Mutex);
            if(milliseconds != -1)
            {
                result = Condition.timed_wait (lock, &time);
            }
            else
            {
                Condition.wait (lock);
            }
        } while(result == 0 && !State);
            
        if (result == 0)
        {
            State = false;
        }
    }

    Mutex.unlock ();
        
    return result;
}

当我试图编译上面的代码时,我得到了timed_wait()的以下内容:

代码语言:javascript
复制
/usr/include/boost/interprocess/sync/interprocess_condition:119:41 required from 'bool boost::interprocess::interprocess_condition::timed_wait (L&, const boost::posix_time::ptime&) [with L=boost::interprocess::interprocess_mutex]'
/usr/include/boost/interprocess/sync/detail/locks.hpp:27:60 error no type named 'mutex_type' in 'class::boost::interprocess_mutex'

我相信我的声明和使用都是正确的,但显然有些地方是不正确的。在过去的几天里,我一直在撕扯我的头发,试图弄清楚这件事,但我什么也没有得到。我想有一些助推大师可以解决/解释我没有得到的事情。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-30 17:44:43

我在do...while()中添加了一个do...while(),替换了timed_wait()和timed_wait()调用中的Mutex。这解决了我的编译器问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63124443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档