Mat Data in Multithreading
In my code , I use sockets to offload processing of a Mat Image onto another machine, and wait for the result to be read back. So in end up with resulting the Mat Image.
I use fork() to create a child process to take care of the sending and receiving of this Mat image.
Mat image = imread( "image_source" );
Mat result;
fork()
if( child_process ){
// OVER SIMPLIFYING:
open socket();
send( image.data );
receive( result.data );
}
if( parent_process ){
wait();
imshow( result ) ;
}
The socket programming works fine and the child thread gets the correct information (verified). Obviously I need to access the resulting image from the parent thread and NOT the child thread only.
The parent thread keeps wait indefinitely, as Mat result is never populated.
Do I need to use some form of shared memory ? Or is that bad practice when using threads ?
This is unrelated to OpenCV. If you want to use multithreaded code, you better start by learning about how to use it properly: threads, mutexes, condition variables and signals, etc. Shared memory is fine as long as you take care...
fork() works on its own copy of the parent env. (you probably want threads instead of a fork)