Hello,
I would like to solve the following problem. On the server side I have
a file with a sequence of natural numbers (1, 2, 3, 4, 5, ...., n).
Each user, after some action, adds new number (n+1, where n is the last
number in the file) to the end of file. To do this user has to open the
file for reading, read the last number, perform corresponding
manipulations with the extracted last number and add result to the end
of the file (after opening it for adding). However, it can happens that
during one user performs algebraic calculation with the last extracted
number, some another user opens the file with numbers, performs the
same algebraic manipulation, and adds result to the end of file.
Afterwards, the first user finishes his calculation and adds the same
number to the file. I would like to avoid this situation. My solution
is to keep file opened during algebraic calculations. It is the
sequence should be the following. Open file, read the last number, with
the usage of the last number calculate next number, add this new
calculated number to the end of the file, close the file.
The first my question is whether one can do it. I mean can one open
file for both reading and adding? If yes, how one need to do it? And
the last question is whether it helps to solve my problem? I mean, is
it thru that during file is opened by one user, another user cannot
read and change this file?
Thank you.
I would like to solve the following problem. On the server side I have
a file with a sequence of natural numbers (1, 2, 3, 4, 5, ...., n).
Each user, after some action, adds new number (n+1, where n is the last
number in the file) to the end of file. To do this user has to open the
file for reading, read the last number, perform corresponding
manipulations with the extracted last number and add result to the end
of the file (after opening it for adding). However, it can happens that
during one user performs algebraic calculation with the last extracted
number, some another user opens the file with numbers, performs the
same algebraic manipulation, and adds result to the end of file.
Afterwards, the first user finishes his calculation and adds the same
number to the file. I would like to avoid this situation. My solution
is to keep file opened during algebraic calculations. It is the
sequence should be the following. Open file, read the last number, with
the usage of the last number calculate next number, add this new
calculated number to the end of the file, close the file.
The first my question is whether one can do it. I mean can one open
file for both reading and adding? If yes, how one need to do it? And
the last question is whether it helps to solve my problem? I mean, is
it thru that during file is opened by one user, another user cannot
read and change this file?
Thank you.
Comment