I am writing a program, which has one write thread, and a few read threads, that write/read to a file on disk. I wish that no write / read will happen at the same time. I found many examples which uses pthread mutex lock to protect memory array during write / read, such as declaring the protected memory array volatile.
volatile int array[NUMBER];
pthread_mutex_t locks[NUMBER];
pthread_mutex_lock(&locks[index]);
array[acct] -= SOME_NUMBER;
pthread_mutex_unlock(&locks[index]);
But I cannot find examples with using pthreads to protect files on disk.
volatile FILE* array[NUMBER]; ??
Can someone point me to the right direction? I wish write / read threads will not access the files on disk simultaneously.
Edit: I read more, and according to this post, it seems that multithreading does not work with disk IO.