I need to implement the following module using C programming on both Solaris and Windows.
1. The module will be used by multiple processes;
2. The module calls an existing batch file from time to time;
3. The batch file provides some output information that will be parsed by its caller;
It may take a few seconds for the batch file to complete its execution. Hence to speed up, I need to implement a caching mechanism for the outputs of the batch file. This way the first caller of the batch file writes the outputs to a cache file, the following caller can then just open the cache file to get the information. I will also use a timeout parameter to decide if the cached information is expired and if so the batch file will be re-executed to refresh the cache.
My question is, how should I synchronize the read and write operation of the cache file? Read/write locks, semaphore, or something else?