#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM_THREADS 8
typedef struct
{
long threadid;
int exoid;
} param;
void *error_test(void *varg)
{
param *arg = (param *)varg;
int i = 0;
char name[32];
const char *routine;
const char *message;
int err_num;
snprintf(name, 32, "Thread%ld", arg->threadid);
ex_err(name,
"Testing thread-safe exodus", i);
if (err_num != i) {
fprintf(stderr, "Thread %ld: ERROR: called error (%d) does not match stored value (%d)\n",
arg->threadid, i, err_num);
}
}
for (i = NC_EBADID; i >= NC4_LAST_ERROR; i--) {
ex_err(name,
"Testing thread-safe exodus", i);
if (err_num != i) {
fprintf(stderr, "Thread %ld: ERROR: called error (%d) does not match stored value (%d)\n",
arg->threadid, i, err_num);
}
}
return arg;
}
int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
param arg[NUM_THREADS];
printf("Running on %d threads\n", NUM_THREADS);
for (long t = 0; t < NUM_THREADS; t++) {
arg[t].threadid = t;
int rc = pthread_create(&threads[t], NULL, error_test, (void *)(arg + t));
if (rc) {
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
for (long t = 0; t < NUM_THREADS; t++) {
pthread_join(threads[t], NULL);
}
}
@ EX_INTERNAL
Definition exodusII.h:1953
@ EX_MEMFAIL
Definition exodusII.h:1947
void ex_get_err(const char **msg, const char **func, int *err_num)
Definition ex_err.c:299
void ex_err(const char *module_name, const char *message, int err_num)
Definition ex_err.c:90