#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;
sprintf(name, "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];
int rc;
long t;
param arg[NUM_THREADS];
printf("Running on %d threads\n", NUM_THREADS);
for (t = 0; t < NUM_THREADS; t++) {
arg[t].threadid = t;
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 (t = 0; t < NUM_THREADS; t++) {
pthread_join(threads[t], NULL);
}
}