0

I'd like change thread safe circular buffer that i saw here, adding a predicate at the condition variable like in this article.

I need to go out of my wait condition after a lot of time with the buffer empty.... so this is my circular-buffer-template snapshot :

//Template of CIRCULAR BUFFER thread-safe

template <typename T>
class circ_buffer : private boost::noncopyable{
public:
    typedef boost::mutex::scoped_lock lock;

    circ_buffer(){}
    circ_buffer(int n){cb.set_capacity(n);}

 ........

  struct cb_not_empty{
        boost::circular_buffer<T>& circ_buf;

        cb_not_empty(boost::circular_buffer<T>& circular_buffer_):
            circ_buf(circular_buffer_){}

        bool operator ()() const{
            return !circ_buf.empty();
        }
    };

    template<typename Duration>
    bool timed_wait_and_pop(T& popped_valued,Duration const& wait_duration){
        lock lk(monitor);
        if(!buffer_not_empty.timed_wait(lk,wait_duration,cb_not_empty(the_cb)))
            return false;
        popped_valued = the_cb.front();
        the_cb.pop();
        return true;
    }

 .......

private:
    boost::condition            buffer_not_empty;
    boost::mutex                monitor;
    boost::circular_buffer<T>   cb;
    std::atomic<bool>           circ_buf_flag;   //flag to turn ON/OFF circular buffer: make circ_buf OFF to go out

};

my gnu compiler give me

error: 'the_cb' was not declared in this scope
         if(!buffer_not_empty.timed_wait(lk,wait_duration,cb_not_empty(the_cb)))
                                                                       ^ 
Community
  • 1
  • 1
user3371854
  • 103
  • 4
  • When you talk about a thread-safe buffer, it's usually good to say whether you have to support one reader or many (and similarly, one writer or many). – Ben Voigt Sep 12 '14 at 15:58
  • And to answer your question, read the error message. Find where you expected that variable to be declared. And be very careful about things like spelling, underscored, and `the`. – Ben Voigt Sep 12 '14 at 16:00
  • `the_cb` doesn't seem to ne defined in the code shown. Why do you think it should be defined at the point of error? – hyde Sep 12 '14 at 16:00
  • @Casey I'll be more careful, i have not understood -4 blanks- format – user3371854 Sep 13 '14 at 12:41
  • @hyde yes... I've not understood keyword "the_cb" (..the_queue in that articles) should be my cb private variable... – user3371854 Sep 13 '14 at 13:05
  • @user3371854 `the_cb` is not a [keyword](http://en.wikipedia.org/wiki/C_syntax#Reserved_keywords). It is an *identifier*, which must be declared and defined somewhere. – hyde Sep 13 '14 at 17:10

0 Answers0