HDF5: infinite loop closing library


#1

We get the following error when closing the HDF5 library. If the number of attributes is small, this code works. For my computer this succeeds with 20 attributes, but fails at 100.

HDF5: infinite loop closing library L,T_top,P,P,FD,E,SL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL,FL

Example code
#include <stdlib.h>
#include
#include
#include <inttypes.h>
#include
#include “hdf5.h”

using namespace std;

int main(int argc, char* argv[])
{
try {
string file_name = “C:/temp/attr_test.cx5”;
size_t attribute_count = 100;

	// create file
	hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
	H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
	hid_t file_property_list = H5Pcreate(H5P_FILE_CREATE);
	H5Pset_link_creation_order(file_property_list, H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
	H5Pset_attr_creation_order(file_property_list, H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
	H5Pset_attr_phase_change(file_property_list, 0, 0);
	hid_t file_id = H5Fcreate(file_name.c_str(), H5F_ACC_TRUNC, file_property_list, fapl);				
	H5Fclose(file_id);
	H5Pclose(file_property_list);

	
	// create group
	file_id = H5Fopen(file_name.c_str(), H5F_ACC_RDWR, fapl);
	unsigned flags = H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED;
	hid_t group_property_list = H5Pcreate(H5P_GROUP_CREATE);
	H5Pset_link_creation_order(group_property_list, flags);
	H5Pset_attr_creation_order(group_property_list, flags);
	H5Pset_attr_phase_change(group_property_list, 0, 0);
	hid_t group_id = H5Gcreate2(file_id, "root", H5P_DEFAULT, group_property_list, H5P_DEFAULT);		
	H5Pclose(group_property_list);

	// create attributes (decrementing name to validate creation order
	for (int64_t i = attribute_count; i >= 0; i--) {
		hid_t space_id = H5Screate(H5S_SCALAR);			
		//hid_t type_id = H5Tcopy(H5T_IEEE_F32LE);
		hid_t type_id = H5Tcopy(H5T_NATIVE_FLOAT);

		stringstream ss;
		ss << i;
		string attribute_name = ss.str();
		hid_t attribute_id = H5Acreate2(group_id, attribute_name.c_str(), type_id, space_id, H5P_DEFAULT, H5P_DEFAULT);
		float value = i;
		herr_t status = H5Awrite(attribute_id, type_id, &value);
		status = H5Aclose(attribute_id);
		status = H5Tclose(type_id);
		status = H5Sclose(space_id);
	}
	H5Gclose(group_id);

	// delete attributes	
	for (size_t i = 0; i < attribute_count; i++) {			
		group_id = H5Gopen(file_id, "root", H5P_DEFAULT);
		stringstream ss;
		ss << i;
		string attribute_name = ss.str();
		H5Adelete(group_id, attribute_name.c_str());			
		H5Gclose(group_id);
	}
	H5Fclose(file_id);
	H5Pclose(fapl);
}

catch (exception &exception) {
	cout << "Error " << exception.what() << endl;
}
catch (...) {
	cout << "Unknown Exception";
}
return 0;

}