1
1

Fix to the fix -- Brian and I agree that this is a better fix.

This commit was SVN r5693.
Этот коммит содержится в:
Jeff Squyres 2005-05-12 02:44:20 +00:00
родитель 3bd7e72608
Коммит 722ee2103b

Просмотреть файл

@ -33,16 +33,9 @@ int64_t val64 = 0;
#endif #endif
int valint = 0; int valint = 0;
typedef union {
int value;
void *ptr;
} ip_union_t;
static void* atomic_math_test(void* arg) static void* atomic_math_test(void* arg)
{ {
ip_union_t *ip = (ip_union_t*) arg; int count = *((int*) arg);
int count = ip->value;
int i; int i;
for (i = 0 ; i < count ; ++i) { for (i = 0 ; i < count ; ++i) {
@ -60,10 +53,10 @@ static void* atomic_math_test(void* arg)
static int static int
atomic_math_test_th(int count, int thr_count) atomic_math_test_th(int count, int thr_count)
{ {
int value;
#if OMPI_HAVE_POSIX_THREADS #if OMPI_HAVE_POSIX_THREADS
pthread_t *th; pthread_t *th;
int tid, ret = 0; int tid, ret = 0;
ip_union_t ip;
th = (pthread_t *) malloc(thr_count * sizeof(pthread_t)); th = (pthread_t *) malloc(thr_count * sizeof(pthread_t));
if (!th) { if (!th) {
@ -76,9 +69,10 @@ atomic_math_test_th(int count, int thr_count)
we're waiting for all the threads to finish before leaving this we're waiting for all the threads to finish before leaving this
function, so there's no race condition of the instance function, so there's no race condition of the instance
disappearing before the threads start. */ disappearing before the threads start. */
ip.value = count; value = count;
for (tid = 0; tid < thr_count; tid++) { for (tid = 0; tid < thr_count; tid++) {
if (pthread_create(&th[tid], NULL, atomic_math_test, (void*) &ip) != 0) { if (pthread_create(&th[tid], NULL, atomic_math_test,
(void*) &value) != 0) {
perror("pthread_create"); perror("pthread_create");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -97,10 +91,9 @@ atomic_math_test_th(int count, int thr_count)
return ret; return ret;
#else #else
ip_union_t ip; value = count;
ip.value = count;
if (thr_count == 1) { if (thr_count == 1) {
atomic_math_test((void*) &ip); atomic_math_test((void*) &value);
} else { } else {
return 77; return 77;
} }