Note that there are some explanatory texts on larger screens.

plurals
  1. POSemaphores and locks in MATLAB
    primarykey
    data
    text
    <p>I am working on a MATLAB project where I would like to have two instances of MATLAB running in parallel and sharing data. I will call these instances <code>MAT_1</code> and <code>MAT_2</code>. More specifically, the architecture of the system is:</p> <ol> <li><code>MAT_1</code> processes images sequentially, reading them one by one using <code>imread</code>, and outputs the result for each image using <code>imwrite</code>.</li> <li><code>MAT_2</code> reads the images output by <code>MAT_1</code> using <code>imread</code> and outputs its result somewhere else.</li> </ol> <p>One of the problems I think I need to address is to guarantee that <code>MAT_2</code> reads an image output by <code>MAT_1</code> once <code>MAT_1</code> has fully finished writing to it. </p> <p>My questions are: </p> <ol> <li>How would you approach this problem? Do I need to use semaphores or locks to prevent race conditions?</li> <li>Does MATLAB provide any mechanism to lock files? (i.e. something similar to <a href="http://manpages.ubuntu.com/manpages/natty/en/man1/flock.1.html"><code>flock</code></a>, but provided by MATLAB directly, and that works on multiple platforms, e.g. Windows &amp; Linux). If not, do you know of any third-party library that I can use to build this mechanism in MATLAB?</li> </ol> <h3>EDIT :</h3> <ul> <li>As @yoda points out below, the Parallel Computing Toolbox (PCT) allows for blocking calls between MATLAB workers, which is great. That said, I am particularly interested in solutions that do not require the PCT.</li> <li><p>Why do I require <code>MAT_1</code> and <code>MAT_2</code> to run in parallel threads?:</p> <p>The processing done in <code>MAT_2</code> is slower on average (and more prone to crashing) than <code>MAT_1</code>, and the output of <code>MAT_1</code> feeds other programs and processes (including human inspection) that do not need to wait for <code>MAT_2</code> to do its job. </p></li> </ul> <h3>Answers :</h3> <ul> <li>For a solution that allows for the implementation of semaphores but does not rely on the PCT see Jonas' answer below</li> <li>For other good approaches to the problem, see Yoda's answer below</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload