c++ - Multithread ifstream/ofstream -


i have single "resource module" class manages resources application, , reads single file "resources.dat" is.

all objects request new data file go through resourcemodule can manage memory , avoid duplicate resources.

void somefunction() {     image* newimage = new image();     newimage->load("imagename"); }  void image::load(string imagename) {     //pointer image data     _myimage = resourcemodule::getresource(imagename); } 

there's 1 resourcemodule. want make multithread safe, when getresource(string resourcename) called, doesn't bug out.

if this:

image* resourcemodule::getresource(string imagename) {     ifstream filereader;     filereader.open("resources.dat", ios::binary);     if(filereader.is_open())     {         //do reading, return pointer     } } 

is multithread safe? multiple ifstreams/ofstreams conflict each other when declare them , read same file?

no

it work read only, every instance of ifstream read. not problem. every ifstream have it's own position in file, , progress in parallel.

you don't need anything


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -