PPL管道中的访问冲突

时间:2012-01-27 03:11:53

标签: c++ concurrency gdi+ agents

我正在使用异步代理库来实现简单的图像处理管道 我有三个代理人

  1. CLoadBitmapAgent
  2. CConvertToGrayAgent
  3. CSaveBitmapAgent
  4. 每个run()函数如下

    void CLoadBitmapAgent::run()
    {
    Bitmap *pSourceBitmap = new Bitmap(m_imagePath);
    asend(m_target,pSourceBitmap);
    done();
    }
    
    void CConvertToGrayAgent::run()
    {
    BitmapUtilities bitmapUtilities;
    Bitmap *pSourceBitmap = receive(m_source);
    bitmapUtilities.ParallelConvertToGray(pSourceBitmap);
    asend(m_target,pSourceBitmap);
    done();
    
    }
    
    void CSaveBitmapAgent::run()
    {
    Bitmap * bitmap = receive(m_source);
    BitmapUtilities bitmapUtilities;
    CLSID clsid; 
    bitmapUtilities.GetEncoderClsid(L"image/jpeg",clsid);
    bitmap->Save(L"D:\\final_image.jpg",&clsid);
    done();
    }
    

    这是我测试此管道的代码

        wchar_t * wcs = L"D:\\Photos\\z.jpg";
    
    
        unbounded_buffer<Bitmap*> buffer1;
        unbounded_buffer<Bitmap*> buffer2;
    
    
        CLoadBitmapAgent loadBitmapAgent(wcs,buffer1);
        CConvertToGrayAgent convertToGrayAgent(buffer1,buffer2);
        CSaveBitmapAgent saveBitmapAgent(buffer2);
    
        loadBitmapAgent.start();
        convertToGrayAgent.start();
        saveBitmapAgent.start();
        agent * agents[3] = {&loadBitmapAgent,&convertToGrayAgent,&saveBitmapAgent};
        agent::wait_for_all(4,agents);
    

    问题是我在此行中遇到访问冲突异常     剂:: wait_for_all(4,代理); 是什么导致这个异常,我该如何解决它 谢谢

0 个答案:

没有答案