c - Preventing threads from writing to the same file -


I am implementing an FTP-like protocol in Linux kernel 2.4 (homework), and I have this assumption that if The file is open to write any later attempt to open it by another thread, unless I actually try to do it and it is searched

How do I get it Stop it?

PS: I am using Open () to open the file.

PS2: I should be able to reach the existing files. I just want to stop writing them together.

You can keep a list of open files, and then to see before opening a file check Whether it has already been opened by another thread. There are some problems with this approach:

  • To make sure the list is thread-safe, you need to use mutes such as a synchronization primitive, etc.

  • Once your program ends with them, the file will need to be removed from the list.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -