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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -