Answer the question
In order to leave comments, you need to log in
Is it possible to simultaneously write data to one file?
Hello
, I've been thinking about this. Let's say I posted a function to write the data entered from the form to a file. Two users at the same time, to within milliseconds, did the same action - they pressed the submit data button. What will happen - will the data be written to the file or not, and why?
Answer the question
In order to leave comments, you need to log in
if the work with files is organized correctly, then one will wait a little while the other writes.
if everything is completely sad, then the principle "who is the last is the dad" will work.
In race conditions, the best option is the database, the file requires clear access regulations.
Two users at the same time, to within milliseconds, did the same action - they pressed the submit data button. What will happen - will the data be written to the file or not, and why?
Based on the question, it is difficult to understand how your application is planned and how error handling is built, but in any case, you need to somehow mark which user made the addition of information.
If you have a server, then you can accumulate data in the buffer before writing. If a desktop application - store files in a separate user directory, next to the program.
In any case, files are not the best way to store information, since they do not have a strict structure (as well as indexing, meta-information and the ability to access information using queries).
If you do not use databases, then usually data storage tasks are followed by data search and modification tasks, and you yourself will need to implement the algorithms necessary for this. And this requires a fairly good knowledge of the principles of storing data in files (Flat-file Database, File Storage, etc.)
In addition, it will be necessary to implement a mechanism for file ownership (locks, limits on time and access rights) to avoid " race conditions" (parallel work of several users with one file).
Two users at the same time, to within milliseconds, did the same action - they pressed the submit data button. What will happen - will the data be written to the file or not, and why?Nichrome will not come out. The fundamental limitation of physics is Heisenberg's uncertainty principle for action (the product of energy and time).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question