about two or more processes ReadWrite a file simultaneity?
-
like this: 1.When No.1 process reading a.txt, No.2 process read a.txt simultaneity, both read as usual. 2.When No.1 process reading a.txt, No.2 process write a.txt, No.2 process wait No.1 process read complete then write. 3.When No.1 process writting a.txt, No.2 process read a.txt, No.2 process wait No.1 process write complete then read. 4.When No.1 process writting a.txt, No.2 process write a.txt, No.2 process wait No.1 process write complete then write. How use
_locking
(CRT functions) orLockFile
,UnlockFile
(Window API) finish above. it puzzled me someday. If somebody know, please tell me.Thanks very much. -
like this: 1.When No.1 process reading a.txt, No.2 process read a.txt simultaneity, both read as usual. 2.When No.1 process reading a.txt, No.2 process write a.txt, No.2 process wait No.1 process read complete then write. 3.When No.1 process writting a.txt, No.2 process read a.txt, No.2 process wait No.1 process write complete then read. 4.When No.1 process writting a.txt, No.2 process write a.txt, No.2 process wait No.1 process write complete then write. How use
_locking
(CRT functions) orLockFile
,UnlockFile
(Window API) finish above. it puzzled me someday. If somebody know, please tell me.Thanks very much.use some global flags(may be two or three), which indicate the state of the other thread. say for example, int process1flag=0,process2flag=0; and make the flag 1 if it is writing and make it 2 if it is reading. after write or read operations, reset them to 0. observe the same in the other process and take the decission depending on the flags.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
-
like this: 1.When No.1 process reading a.txt, No.2 process read a.txt simultaneity, both read as usual. 2.When No.1 process reading a.txt, No.2 process write a.txt, No.2 process wait No.1 process read complete then write. 3.When No.1 process writting a.txt, No.2 process read a.txt, No.2 process wait No.1 process write complete then read. 4.When No.1 process writting a.txt, No.2 process write a.txt, No.2 process wait No.1 process write complete then write. How use
_locking
(CRT functions) orLockFile
,UnlockFile
(Window API) finish above. it puzzled me someday. If somebody know, please tell me.Thanks very much.You should use some synchronization with the help of Mutex. Check
CreateMutex(), WaitForSingleObject() and ReleaseMutex()
. You can find many samples in CP that uses mutex.nave [OpenedFileFinder]
-
use some global flags(may be two or three), which indicate the state of the other thread. say for example, int process1flag=0,process2flag=0; and make the flag 1 if it is writing and make it 2 if it is reading. after write or read operations, reset them to 0. observe the same in the other process and take the decission depending on the flags.
Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.
chandu004 wrote:
which indicate the state of the other thread
He is talking about different process not different thread.
nave [OpenedFileFinder]
-
chandu004 wrote:
which indicate the state of the other thread
He is talking about different process not different thread.
nave [OpenedFileFinder]