M
M
maksqwe2011-06-12 21:47:25
Windows
maksqwe, 2011-06-12 21:47:25

How to correctly implement access to files that are used by two processes?

Good evening everyone!
I write in C++, VS 2008, win32
Here is the question in the topic title. There are two processes, in each process several threads are created (1 thread = 1 file processing), run simultaneously. How to correctly implement access of each thread of different processes to the same file in the most correct way? Actually, “program A” is launched, then “program B” is immediately launched, a thread is created in program A that processes the 1st file, immediately the thread in program B starts reading this 1st file. It is necessary to make it so that the thread of program B can read this file only after the completion of processing by that thread of program A. Something like this :)
At first I thought to implement it through critical sections, but I remembered that they are only within the same process :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SergeyGrigorev, 2011-06-12
@maksqwe

Try to create a mutex for each file being blocked. As far as I remember, they seem to be shared between several processes.

P
Puma Thailand, 2011-06-13
@opium

Make a separate thread with a queue that will receive commands from other threads to manipulate files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question