Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 ?