Hello,
I am trying to read from two different hdf5 files with two different threads (using std::thread) of a thread pool.
Each thread has its dedicated hdf5 file.
However it seems that sometimes the file cannot be opened: According to the visual studio debugger, the error below is raised when the file is opened. Other messages that vary are logged without the debugger.
Exception thrown at 0x00007FFCBBE5EFE2 (hdf5.dll) in HDFMultiThreadTest.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF
Below is the relevant portion of code that opens the file to read the data. The error does not appear when the thread pool only uses 1 thread. I do not understand why there are thead related issues as each thread has its own hdf5 file.
Is there an element that I missed ? Do you know where this error could come from ?
I am using hdf5 1.12.1 on windows. I can provide the full toy example with the Thread Pool if necessary.
Thanks in advance!
double* read_data(int i,int id) {
using namespace H5;
double* points;
// Dataset names are numbers (as strings) in the range 0 to 0 (checked with HDFView)
std::string dataset_name = std::to_string(i);
// Format name depending on thread id
const char* fmt = "benchmark%d.hdf5";
int sz = std::snprintf(nullptr, 0, fmt, id);
std::vector<char> buf(sz + 1); // note +1 for null terminator
std::snprintf(&buf[0], buf.size(), fmt, id);
std::string NAME_DATA_FILE(buf.begin(), buf.end());
// Create filename of file to open
const H5std_string FILE_NAME_BENCHMARK(NAME_DATA_FILE);
H5std_string DATASET_NAME(dataset_name);
// Read data
try {
H5File file(FILE_NAME_BENCHMARK, H5F_ACC_RDONLY); // <- Debugger error here
DataSet dataset_points = file.openDataSet(DATASET_NAME);
DataSpace dataspace_points = dataset_points.getSpace();
hsize_t dims_points[1];
hsize_t rank_points = dataspace_points.getSimpleExtentDims(dims_points);
points = new double[dims_points[0]];
dataset_points.read(points, PredType::NATIVE_DOUBLE);
}
catch (Exception error) {
error.printErrorStack();
exit(1);
}
return points;
}