Last active
February 21, 2020 06:19
-
-
Save eudoxos/494f79852b039da3c20559d263b8b227 to your computer and use it in GitHub Desktop.
Disable HDF5 locking with library version 1.10 (POSIX), clean close
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<H5cpp.h> | |
#include<sys/file.h> | |
#include<iostream> | |
/* With libhdf5 1.10, file gets locked but the lock is not removed at close. | |
Thus opening the file from the same process will fail. | |
This function will force unlock before the file is closed. | |
3 things must be done, in this order: | |
1. flush the file | |
2. unlock | |
3. close | |
*/ | |
void hdf5_unlock_close(H5::H5File& h5file){ | |
#if H5_VERSION_GE(1,11,0) | |
#error "Better use HDF5_USE_FILE_LOCKING=FALSE to disable locking with HDF5>=1.11" | |
#endif | |
h5file.flush(H5F_SCOPE_GLOBAL); | |
int *handle; | |
h5file.getVFDHandle((void**)&handle); | |
int err=flock(*handle,LOCK_UN); | |
if(err) std::cerr<<"flock failed: "<<strerror(errno)); | |
h5file.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment