MATLAB: Multithreading with mex functions

mex

The documentation of MATLAB suggests that it is OK to multithread with mex functions as long as as the mex API is not used. Multithreading and mex
The link above shows an example of a simple counter. We deploy a software tool developed in MATLAB. Much of the computationally intensive code is written in separately compiled FORTRAN or C modules. The MATLAB GUI just kicks off the executable and returns control to the user. When the executable is finished it writes the output to an ASCII text file. Is it possible to write a mex file that is kicked off when the executable is kicked off? That mex file would just be a while loop checking for the existence of the output file. Once the output file exists, the mex file would interrupt or notify that the results are ready. This would be better then our current implementation where the user clicks to load the results; if the data is not ready it just responds with an error saying to wait a little longer. Does anybody know if this is possible? The link aboves says that the mex API may not be used which includes simple things like mexPrintf. That makes me think that this may not be possible.
Any suggestions?

Best Answer

I'm not sure if I've interpreted your question correctly, but I think your main problem is working out how to get data back to MatLab asynchronously.
If that is correct, you can start a MatLab timer before firing off your processing app. The timer can poll once per second to check for the existence of the output, then kill itself and fire off some MatLab callback function once the file shows up... You can also do timeouts etc.
-g-