Some of my friends wrote a program which uses a C program to receive data from network (UDP) and use Matlab to process the data received. Two files viz. 'Data file' and 'Control file' are used to communicate data between Matlab and C. The scheme is as follows.
- The C program receives data from network and if 'Control file' contains '0', writes the received data into 'Data file'. After writing the data completely, '0' in the 'Control file' is replaced with '1'.
- Matlab program checks for '1' in the 'Control file' continuously and reads data from the 'Data file' as soon as it reads '1' in the 'Control file'. After reading and processing the data, Matlab replaces '1' with '0'in the 'Control file'.
Basically the scheme tries to use the 'Control file' as a 'lock' to safely handle the data in 'Data file'. The data is received continuously in every 1 msec and processing need to be in soft real time.
Though it is claimed that everything is working perfectly, I feel something fishy here. In principle, we should use something similar to semaphore to properly lock the resources....right? What are the pitfalls of this scheme? Is there any better alternate schemes?
EDIT: Now I see that somebody suggested a similar 'quick and dirty' technique at Launch one C++ application from another, and communicate with it
I would like to exactly know why this is a 'dirty' technique? Will it succeed in all situations?