使用boost :: thread

时间:2017-03-01 20:01:06

标签: c++ multithreading boost

我正在尝试使用boost :: lock为相机读取添加线程安全性,但我被卡住了。在线程A中,帧编写器,我有:

·H

#include <boost/thread/locks.hpp> 
#include <boost/thread/shared_mutex.hpp> 
#include <boost/system/config.hpp>

typedef boost::shared_mutex Lock;
    typedef boost::unique_lock< Lock > WriteLock;
    typedef boost::shared_lock< Lock > ReadLock;
    Lock OccamLock;

的.cpp

    WriteLock w_lock(OccamLock); 

//calls frames from camera

            cv::Mat f1 = cv::Mat_<uchar>(images[0]->height, images[0]->width, (uchar*)images[0]->data[0], images[0]->step[0]);


            f1.copyTo(img0);

            w_lock.release();
在线程B中,读者,我有:

·H

typedef boost::shared_mutex Lock;
    typedef boost::unique_lock< Lock > WriteLock;
    typedef boost::shared_lock< Lock > ReadLock;

的.cpp

  ReadLock r_lock(oGrab->OccamLock);  //oGrab is the reference to the class in Thread A

                imgs[0] = oGrab->img0;

                r_lock.release();

这是编译,但帧是黑色的。我搞砸了哪里? (我是新手,请原谅白痴)

谢谢。

0 个答案:

没有答案