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
Post a Comment