c# - Multithreaded file reading, does seek & read need critical section? -
i have file read multiple threads, need put each seek , read critical section?
stream.seek(seekstart, seekorigin.begin); stream.read(); stream.seek(seeknext, seekorigin.current); stream.read();
or
lock(filelock) { stream.seek(seekstart, seekorigin.begin); stream.read(); stream.seek(seeknext, seekorigin.current); stream.read(); }
obviously i'm trying avoid following situation:
. . thread a: seek <- preempted -> thread b: seek thread b: read <- preempted -> thread a: read (will reading wrong location?) . .
because streams separate objects in separate threads, should ok without making critical. each stream should hold own seek location, , should not interfere others.
this assumes declaring of variables within class object, , not static.
Comments
Post a Comment