Reputation: 1217
I have two threads that will be accessing multiples files. These two threads might try to access the same file at the same time. How can I guarantee exclusive access to a file in this scenario using pthread functions and structs in C, knowing that there will be a very large number of files that these two threads will be accessing? I know I can create a big number of mutexes, but that doesn't seem like the way to go since there is a limit to that number.
Upvotes: 0
Views: 531
Reputation: 7832
Have each thread place an advisory write-lock the file that's it's about to access using, for example, flock().
Upvotes: 1