我有一个班子试图改变其某些成员的职能,以适应不同的线索。 虽然该方案没有问题,但它在试图从图像缓冲(由不同的透镜更新)中读时坠毁。 如同问题一样,在争论不正确的情况下,就会产生问题。
下面的《法典》应当更明确地解释我试图做些什么。 基本上,我所要完成的是,成员的职能“填充”填补了形象的缓冲,而其他方案正在做其他事情,包括同时阅读同样的图像缓冲。
非常感谢对辛迪加的任何帮助。
const int MaxImgBufferSize = 5;
class MyFrame : public wxFrame
{
public:
// constructors
MyFrame(const wxString& title);
private:
static vector <IplImage*> ImgBuffer;
void changeWP(wxCommandEvent&);
void fillBuffer();
void fillBufferFun();
static void __cdecl getImgFromBuffer(void *);
static void __cdecl pushImgBuffer(void *);
};
vector<IplImage*> MyFrame::ImgBuffer;
enter code here
MyFrame::MyFrame(const wxString& title)
: wxFrame(...)
{
// some stuff here
InitializeCriticalSection(&Section);
fillBuffer();
// some code here calls changeWP(wxCommandEvent&) from time to time
}
void MyFrame::fillBuffer()
{
while(ImgBuffer.size() <= MaxImgBufferSize)
{
fillBufferFun();
}
}
void MyFrame::fillBufferFun()
{
ImgBuffer* img;
// do something with img
_beginthread(pushImgBuffer, 0, img);
}
void MyFrame::pushImgBuffer(void *p)
{
EnterCriticalSection(&Section);
ImgBuffer.push_back( (IplImage*) p );
LeaveCriticalSection(&Section);
}
static unsigned int __stdcall getImgFromBuffer(void *);
void MyFrame::changeWP(wxCommandEvent&)
{
// do someting
IplImage* img = NULL;// new IplImage;
_beginthreadex( NULL, 0, MyFrame::getImgFromBuffer, img, 0, NULL );
// do something with img
fillBuffer();
}
unsigned int MyFrame::getImgFromBuffer(void *p)
{
EnterCriticalSection(&Section);
p = (void *)ImgBuffer[0];
ImgBuffer.erase(ImgBuffer.begin());
LeaveCriticalSection(&Section);
return 0;
}