[問題]以thread 作影像處理與成像的同步問題
開發平台(Platform):
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
最近在開發一個影像處理的演算法,將一個畫面的左右兩部份分別用各自的thread 來處
理, 但是在輸出影像的時候,有兩個主要的問題。
一個是左右畫面不同步的更新,代表display函數讀取影像記憶體的時候,兩個各自的
thread並沒有同時完成。這個有點想不通,因為在main()中,display函式是在影像處理
member function [proc_entro()]之後, 會有這個現象有點奇怪
一個是會發生左右兩邊呈現未處理的影像,而且是隨機發生的,
目前懷疑是記憶體的操作造成這個結果,但是還沒有什麼頭緒,
想請問版上高手們是否有什麼建議呢
其中thread的輸入與輸出都是完整的影像大小(包含左半面及右半面影像),因為成像演算
法左右兩邊是獨立的,所以用兩個thread分別計算
以下是目前的程式架構
main(){
proc* pproc;
//image_buffer 存放待處理影像的位址
//processed_image_buffer 存放處理完影像的位址
pproc->das_entro(image_buffer, processed_image_buffer);
display(processed_image_buffer);
}
proc.cpp
==============================
proc::das_entro(short* image_buffer, short* processed_image_buffer){
thread das_thd1(&proc::das_thd1, this, image_buffer, processed_image_buffer);
thread das_thd2(&proc::das_thd2, this, image_buffer, processed_image_buffer);
das_thd1.join();
das_thd2.join();
return 0;
}
proc::das_thd1(short* image_buffer, short* das_image_buffer){
...
//左半面影像處理
...
return 0;
}
proc::das_thd2(short* image_buffer, short* das_image_buffer){
...
//右半面影像處理
...
return 0;
}
餵入的資料(Input):
image buffer
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.96.70.118
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1454380431.A.6D5.html
※ 編輯: yushengc (140.96.70.118), 02/02/2016 10:34:44
※ 編輯: yushengc (140.96.70.118), 02/02/2016 10:35:17
※ 編輯: yushengc (140.96.70.118), 02/02/2016 10:36:06
→
02/02 11:37, , 1F
02/02 11:37, 1F
→
02/02 12:05, , 2F
02/02 12:05, 2F
→
02/02 13:40, , 3F
02/02 13:40, 3F
→
02/02 13:41, , 4F
02/02 13:41, 4F
→
02/02 14:00, , 5F
02/02 14:00, 5F
→
02/02 14:08, , 6F
02/02 14:08, 6F
→
02/02 15:58, , 7F
02/02 15:58, 7F
→
02/02 15:58, , 8F
02/02 15:58, 8F
→
02/02 16:01, , 9F
02/02 16:01, 9F
→
02/03 10:55, , 10F
02/03 10:55, 10F
推
02/03 11:37, , 11F
02/03 11:37, 11F
→
02/03 11:57, , 12F
02/03 11:57, 12F