2003-04-01 01:59:04 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* Testing thread safety in dataset creation in the HDF5 library
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Set of tests to run multiple threads so that each creates a different
|
|
|
|
* dataset. This is likely to cause race-conditions if run in a non
|
|
|
|
* threadsafe environment.
|
|
|
|
*
|
|
|
|
* Temporary files generated:
|
2000-05-20 07:00:03 +08:00
|
|
|
* ttsafe_dcreate.h5
|
2000-05-19 03:13:33 +08:00
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
#include "ttsafe.h"
|
|
|
|
|
2003-06-26 10:10:33 +08:00
|
|
|
#ifdef H5_HAVE_THREADSAFE
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define FILENAME "ttsafe_dcreate.h5"
|
|
|
|
#define NUM_THREAD 16
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
void *tts_dcreate_creator(void *);
|
|
|
|
|
2000-05-20 07:00:03 +08:00
|
|
|
typedef struct thread_info {
|
2020-09-30 22:27:10 +08:00
|
|
|
int id;
|
|
|
|
hid_t file;
|
|
|
|
const char *dsetname;
|
2005-08-14 04:53:35 +08:00
|
|
|
} thread_info;
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2003-02-08 05:14:19 +08:00
|
|
|
/*
|
|
|
|
* Set individual dataset names (rather than generated the names
|
|
|
|
* automatically)
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
const char *dsetname[NUM_THREAD] = {"zero", "one", "two", "three", "four", "five",
|
|
|
|
"six", "seven", "eight", "nine", "ten", "eleven",
|
|
|
|
"twelve", "thirteen", "fourteen", "fifteen"};
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
thread_info thread_out[NUM_THREAD];
|
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Thread safe test - multiple dataset creation
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
2018-05-14 15:44:02 +08:00
|
|
|
void
|
|
|
|
tts_dcreate(void)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
2010-09-11 00:15:34 +08:00
|
|
|
/* thread definitions */
|
|
|
|
H5TS_thread_t threads[NUM_THREAD];
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* HDF5 data definitions */
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t file = H5I_INVALID_HID;
|
|
|
|
hid_t dataset = H5I_INVALID_HID;
|
|
|
|
int datavalue, i;
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_t attribute;
|
2020-09-30 22:27:10 +08:00
|
|
|
herr_t status;
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* set pthread attribute to perform global scheduling */
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_init(&attribute);
|
|
|
|
|
|
|
|
/* set thread scope to system */
|
2003-02-10 23:38:52 +08:00
|
|
|
#ifdef H5_HAVE_SYSTEM_SCOPE_THREADS
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_setscope(&attribute, H5TS_SCOPE_SYSTEM);
|
2003-02-10 23:38:52 +08:00
|
|
|
#endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a hdf5 file using H5F_ACC_TRUNC access, default file
|
|
|
|
* creation plist and default file access plist
|
|
|
|
*/
|
|
|
|
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
2018-05-14 15:44:02 +08:00
|
|
|
CHECK(file, H5I_INVALID_HID, "H5Fcreate");
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* simultaneously create a large number of datasets within the file */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < NUM_THREAD; i++) {
|
|
|
|
thread_out[i].id = i;
|
|
|
|
thread_out[i].file = file;
|
2003-02-08 05:14:19 +08:00
|
|
|
thread_out[i].dsetname = dsetname[i];
|
2020-09-30 22:27:10 +08:00
|
|
|
threads[i] = H5TS_create_thread(tts_dcreate_creator, NULL, &thread_out[i]);
|
2018-05-14 15:44:02 +08:00
|
|
|
}
|
2003-02-08 05:14:19 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < NUM_THREAD; i++)
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_wait_for_thread(threads[i]);
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* compare data to see if it is written correctly */
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < NUM_THREAD; i++) {
|
|
|
|
if ((dataset = H5Dopen2(file, dsetname[i], H5P_DEFAULT)) < 0) {
|
2004-01-10 09:41:13 +08:00
|
|
|
TestErrPrintf("Dataset name not found - test failed\n");
|
2003-02-08 05:14:19 +08:00
|
|
|
H5Fclose(file);
|
|
|
|
return;
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
else {
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
|
|
|
|
CHECK(status, FAIL, "H5Dread");
|
2003-02-08 05:14:19 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
if (datavalue != i) {
|
|
|
|
TestErrPrintf("Wrong value read %d for dataset name %s - test failed\n", datavalue,
|
|
|
|
dsetname[i]);
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Dclose(dataset);
|
|
|
|
CHECK(status, FAIL, "H5Dclose");
|
|
|
|
status = H5Fclose(file);
|
|
|
|
CHECK(status, FAIL, "H5Fclose");
|
2003-02-08 05:14:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
status = H5Dclose(dataset);
|
2018-05-14 15:44:02 +08:00
|
|
|
CHECK(status, FAIL, "H5Dclose");
|
2003-02-08 05:14:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* close remaining resources */
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Fclose(file);
|
|
|
|
CHECK(status, FAIL, "H5Fclose");
|
2003-02-08 05:14:19 +08:00
|
|
|
|
|
|
|
/* Destroy the thread attribute */
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_destroy(&attribute);
|
2018-05-14 15:44:02 +08:00
|
|
|
} /* end tts_dcreate() */
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
void *
|
|
|
|
tts_dcreate_creator(void *_thread_data)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t dataspace = H5I_INVALID_HID;
|
|
|
|
hid_t dataset = H5I_INVALID_HID;
|
|
|
|
herr_t status;
|
|
|
|
hsize_t dimsf[1]; /* dataset dimensions */
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
struct thread_info thread_data;
|
|
|
|
|
2023-06-30 03:33:46 +08:00
|
|
|
memcpy(&thread_data, _thread_data, sizeof(struct thread_info));
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
|
|
|
|
/* define dataspace for dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
dimsf[0] = 1;
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
dataspace = H5Screate_simple(1, dimsf, NULL);
|
2018-05-14 15:44:02 +08:00
|
|
|
CHECK(dataspace, H5I_INVALID_HID, "H5Screate_simple");
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
|
|
|
|
/* create a new dataset within the file */
|
2020-09-30 22:27:10 +08:00
|
|
|
dataset = H5Dcreate2(thread_data.file, thread_data.dsetname, H5T_NATIVE_INT, dataspace, H5P_DEFAULT,
|
|
|
|
H5P_DEFAULT, H5P_DEFAULT);
|
2018-05-14 15:44:02 +08:00
|
|
|
CHECK(dataset, H5I_INVALID_HID, "H5Dcreate2");
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
|
|
|
|
/* initialize data for dataset and write value to dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &thread_data.id);
|
2018-05-14 15:44:02 +08:00
|
|
|
CHECK(status, FAIL, "H5Dwrite");
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
|
|
|
|
/* close dataset and dataspace resources */
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Dclose(dataset);
|
|
|
|
CHECK(status, FAIL, "H5Dclose");
|
|
|
|
status = H5Sclose(dataspace);
|
|
|
|
CHECK(status, FAIL, "H5Sclose");
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
|
|
|
|
return NULL;
|
2018-05-14 15:44:02 +08:00
|
|
|
} /* end tts_dcreate_creator() */
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
void
|
|
|
|
cleanup_dcreate(void)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
HDunlink(FILENAME);
|
2000-05-19 03:13:33 +08:00
|
|
|
}
|
|
|
|
#endif /*H5_HAVE_THREADSAFE*/
|