c - File locking between threads and processes -
I have a program that produces many processes or threads, each of which writes a line on the file, but Obviously, want to mix T line, so I need specific access to the file.
More specifically, in the first case, I have a process that processes the processes of many children (C1, C2, C3, C4, ...), and I, F, C2 , C3, C4, ... want to block entry ... when C1 is writing.
In the second case, I have the same process that spawns multiple threads (T1, T2, T3, T4, ...) and, again, I have F, T2, I want to block access to T3, T4, ... when T1 is typing.
Imagining a function like a herd () takes care of the first part, but what about thread matter? And what about the Windows platform?
You want to use a locking mechanism. Between threads, a Mute X is the simplest file entry protected by Mute X, so no two threads can try to write the file at the same time.
For the processes, you can use a process-sharing mute x. On windows, you have one.
Comments
Post a Comment