summaryrefslogtreecommitdiffstats
path: root/test/ttsafe_dcreate.c
blob: a3bc7638ca916c882e591719ee033b597b443168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/********************************************************************
 *
 * 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:
 *   ttsafe_dcreate.h5
 *
 * HDF5 APIs exercised in thread:
 * H5Screate_simple, H5Tcopy, H5Tset_order, H5Dcreate, H5Dwrite, H5Dclose,
 * H5Tclose, H5Sclose.
 *
 * Created: Apr 28 2000
 * Programmer: Chee Wai LEE
 *
 * Modification History
 * --------------------
 *
 *	19 May 2000, Bill Wendling
 *	Changed so that it creates its own HDF5 file and removes it at cleanup
 *	time.
 *
 ********************************************************************/
#include "ttsafe.h"

#ifdef H5_HAVE_THREADSAFE

#define FILENAME		"ttsafe_dcreate.h5"
#define DATASETNAME_LENGTH	10
#define NUM_THREAD		16

void *tts_dcreate_creator(void *);

typedef struct thread_info {
	int id;
	hid_t file;
	const char *dsetname;
} thread_info;

/*
 * Set individual dataset names (rather than generated the names
 * automatically)
 */
const char *dsetname[NUM_THREAD]={
    "zero",
    "one",
    "two",
    "three",
    "four",
    "five",
    "six",
    "seven",
    "eight",
    "nine",
    "ten",
    "eleven",
    "twelve",
    "thirteen",
    "fourteen",
    "fifteen"
};

thread_info thread_out[NUM_THREAD];

/*
 **********************************************************************
 * Thread safe test - multiple dataset creation
 **********************************************************************
 */
void tts_dcreate(void)
{
    /* Pthread definitions */
    pthread_t threads[NUM_THREAD];

    /* HDF5 data definitions */
    hid_t file, dataset;
    int datavalue, i;
    pthread_attr_t attribute;
    int ret;

    /* set pthread attribute to perform global scheduling */
    ret=pthread_attr_init(&attribute);
    assert(ret==0);
#ifdef H5_HAVE_SYSTEM_SCOPE_THREADS
    ret=pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM);
    assert(ret==0);
#endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */

    /*
     * 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);
    assert(file>=0);

    /* simultaneously create a large number of datasets within the file */
    for (i = 0; i < NUM_THREAD; i++) {
        thread_out[i].id = i;
        thread_out[i].file = file;
        thread_out[i].dsetname = dsetname[i];
        ret=pthread_create(&threads[i], NULL, tts_dcreate_creator, &thread_out[i]);
        assert(ret==0);
    }

    for (i = 0;i < NUM_THREAD; i++) {
        ret=pthread_join(threads[i], NULL);
        assert(ret==0);
    } /* end for */

    /* compare data to see if it is written correctly */

    for (i = 0; i < NUM_THREAD; i++) {
        if ((dataset = H5Dopen(file,dsetname[i])) < 0) {
            TestErrPrintf("Dataset name not found - test failed\n");
            H5Fclose(file);
            return;
        } else {
            ret=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue);
            assert(ret>=0);

            if (datavalue != i) {
                TestErrPrintf("Wrong value read %d for dataset name %s - test failed\n",
                            datavalue, dsetname[i]);
                H5Dclose(dataset);
                H5Fclose(file);
                return;
            }

            ret=H5Dclose(dataset);
            assert(ret>=0);
        }
    }

    /* close remaining resources */
    ret=H5Fclose(file);
    assert(ret>=0);

    /* Destroy the thread attribute */
    ret=pthread_attr_destroy(&attribute);
    assert(ret==0);
}

void *tts_dcreate_creator(void *_thread_data)
{
	hid_t   dataspace, dataset;
        herr_t  ret;
	hsize_t dimsf[1]; /* dataset dimensions */
	struct thread_info thread_data;

	memcpy(&thread_data,_thread_data,sizeof(struct thread_info));

	/* define dataspace for dataset */
	dimsf[0] = 1;
	dataspace = H5Screate_simple(1,dimsf,NULL);
        assert(dataspace>=0);

	/* create a new dataset within the file */
	dataset = H5Dcreate(thread_data.file, thread_data.dsetname,
			    H5T_NATIVE_INT, dataspace, H5P_DEFAULT);
        assert(dataset>=0);

	/* initialize data for dataset and write value to dataset */
	ret=H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
		 H5P_DEFAULT, &thread_data.id);
        assert(ret>=0);

	/* close dataset and dataspace resources */
	ret=H5Dclose(dataset);
        assert(ret>=0);
	ret=H5Sclose(dataspace);
        assert(ret>=0);

	return NULL;
}

void cleanup_dcreate(void)
{
	HDunlink(FILENAME);
}
#endif /*H5_HAVE_THREADSAFE*/
e_desc Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* * generic/tclBasic.c: TIP #280 implementation, conditional on the define TCL...andreas_kupries2006-11-2818-56/+2611
* * unix/tclUnixChan.c (TclUnixWaitForFile):Kevin B Kenny2006-11-283-4/+222
* * tcl.m4 (Linux): --enable-64bit support. [Patch 1597389], [Bug 1230558]das2006-11-263-329/+382
* * unix/tclUnixFCmd.c (CopyFile): [SF Tcl Bug 1586470]. Added codeandreas_kupries2006-11-072-1/+17
* * generic/tclBasic.c (TEOVI): fix por possible leak of a CommandMiguel Sofer2006-11-043-13/+46
* * generic/tclEnv.c (Darwin): mark _environ symbol as unexported.das2006-10-312-1/+6
* Fix bug #1582769 build with VC2003 and correct i386 arch.patthoyts2006-10-312-2/+9
* * README: Bump version number to 8.4.15dgp2006-10-2310-16/+29
* advance 8.4.14 tagcore_8_4_14dgp2006-10-181-2/+2
* Ensure builds with VC6 without Platform SDK and Pickup MACHINE from environmentpatthoyts2006-10-183-11/+24
* * generic/tclIOUtil.c: Cleaned up some code flagged by adgp2006-10-175-20/+25
* Set release datedgp2006-10-161-2/+2
* * macosx/Makefile: don't redo prebinding of non-prebound binaires.das2006-10-162-4/+9
* * changes: updates for 8.4.14 release.das2006-10-162-3/+9
* * generic/tclPkg.c (Tcl_PkgRequireEx): Corrected crash whenandreas_kupries2006-10-112-8/+18
* * changes: changes updated for 8.4.14 release.dgp2006-10-102-2/+28
* dup test namedgp2006-10-101-2/+2
* update tests to handle strictness changehobbs2006-10-062-1/+18
* Remove RTCc flagpatthoyts2006-10-063-7/+7
* note default "false" for http::strict for 8.4hobbs2006-10-061-1/+1
* * library/http/http.tcl (http::geturl): only do geturl url rfchobbs2006-10-062-4/+12
* (UnicodeToUtfProc): dst must be set to (ch & 0xFF) to work on big endian systemshobbs2006-10-061-2/+2
* * generic/tcl.h: note limitation on changing Tcl_UniChar sizehobbs2006-10-054-29/+52
* * generic/tclVar.c (Tcl_LappendObjCmd):Miguel Sofer2006-10-05