Suppose, that in a node.js program or any other asynchronous program in linux environment, I have a function "fun", that gets called and reads a file "X" for some quantity of bytes in a asynchronous way. This implies that IO disk operation gets to disk scheduler queue.
Then the single thread program continues and another function "fun1" gets called. "fun1" writes something in the file "X".
The single thread program continues doing something else.
Can the scenario like this happen: disk scheduler throws "the reading" called by "fun" in the middle of its read to its queue, and starts "writing" which was called by "fun1". It writes to files "X" beginning and finishes, then "the reading" again continues reading, finished, and returns to "fun" callback. The text read from "X" that "fun" returned is old and not affected by what "fun1" wrote.
Or is it
If it can, is it file locking the solution to the cases like this?