Index: parallel.c
===================================================================
--- parallel.c	(revision 54086)
+++ parallel.c	(working copy)
@@ -164,7 +164,13 @@
 } bu_taskcontrol[MAX_PSW];
 #endif
 
+struct thread_data {
+    void (*user_func)(int, genptr_t);
+    genptr_t user_arg;
+    int cpu_id;
+};
 
+
 void
 bu_nice_set(int newnice)
 {
@@ -585,13 +591,16 @@
 HIDDEN void
 parallel_interface(void)
 {
-    register int cpu;		/* our CPU (thread) number */
+    struct thread_data user_thread_data_pi;
 
+    user_thread_data_pi.user_func = parallel_func;
+    user_thread_data_pi.user_arg  = parallel_arg; 
+
     bu_semaphore_acquire(BU_SEM_SYSCALL);
-    cpu = parallel_nthreads_started++;
+    user_thread_data_pi.cpu_id = parallel_nthreads_started++;
     bu_semaphore_release(BU_SEM_SYSCALL);
 
-    (*parallel_func)(cpu, parallel_arg);
+    parallel_interface_arg(&user_thread_data_pi);
 
     bu_semaphore_acquire(BU_SEM_SYSCALL);
     parallel_nthreads_finished++;
@@ -607,6 +616,12 @@
     if (cpu) _exit(0);
 #  endif /* SGI */
 }
+
+HIDDEN void
+parallel_interface_arg(struct thread_data *user_thread_data)
+{
+    (*((*user_thread_data).user_func))((*user_thread_data).cpu_id, (*user_thread_data).user_arg);
+}
 #endif /* PARALLEL */
 
 #ifdef SGI_4D
@@ -631,6 +646,8 @@
 void
 bu_parallel(void (*func)(int, genptr_t), int ncpu, genptr_t arg)
 {
+    struct thread_data user_thread_data_bu[ncpu];
+
 #ifndef PARALLEL
 
     bu_log("bu_parallel(%d., %p):  Not compiled for PARALLEL machine, running single-threaded\n", ncpu, arg);
@@ -691,6 +708,13 @@
     parallel_func = func;
     parallel_arg = arg;
 
+    /* Fill in the data of user_thread_data_bu structures of all threads */
+    for(x = 0; x < ncpu; x++) {
+	user_thread_data_bu[x].user_func = func;
+	user_thread_data_bu[x].user_arg  = arg;
+	user_thread_data_bu[x].cpu_id    = x;
+    }
+
     /* if we're in debug mode, allow additional cpus */
     if (!(bu_debug & BU_DEBUG_PARALLEL)) {
 	avail_cpus = bu_avail_cpus();
@@ -928,11 +952,11 @@
     /* Create the threads */
     for (x = 0; x < ncpu; x++) {
 
-	if (thr_create(0, 0, (void *(*)(void *))parallel_interface, 0, 0, &thread)) {
+	if (thr_create(0, 0, (void *(*)(void *))parallel_interface_arg, &user_thread_data_bu[x], 0, &thread)) {
 	    fprintf(stderr, "ERROR: bu_parallel: thr_create(0x0, 0x0, 0x%x, 0x0, 0, 0x%x) failed on processor %d\n",
-		    parallel_interface, &thread, x);
+		    parallel_interface_arg, &thread, x);
 	    bu_log("ERROR: bu_parallel: thr_create(0x0, 0x0, 0x%x, 0x0, 0, 0x%x) failed on processor %d\n",
-		   parallel_interface, &thread, x);
+		   parallel_interface_arg, &thread, x);
 	    /* Not much to do, lump it */
 	} else {
 	    if (UNLIKELY(bu_debug & BU_DEBUG_PARALLEL))
@@ -1003,17 +1027,17 @@
 	pthread_attr_init(&attrs);
 	pthread_attr_setstacksize(&attrs, 10*1024*1024);
 
-	if (pthread_create(&thread, &attrs, (void *(*)(void *))parallel_interface, NULL)) {
-	    fprintf(stderr, "ERROR: bu_parallel: thr_create(0x0, 0x0, 0x%lx, 0x0, 0, 0x%lx) failed on processor %d\n",
-		    (unsigned long int)parallel_interface, (unsigned long int)&thread, x);
-	    bu_log("ERROR: bu_parallel: thr_create(0x0, 0x0, 0x%lx, 0x0, 0, %p) failed on processor %d\n",
-		   (unsigned long int)parallel_interface, (void *)&thread, x);
+	if (pthread_create(&thread, &attrs, (void *(*)(void *))parallel_interface_arg, &user_thread_data_bu[x])) {
+	    fprintf(stderr, "ERROR: bu_parallel: pthread_create(0x0, 0x0, 0x%lx, 0x0, 0, 0x%lx) failed on processor %d\n",
+		    (unsigned long int)parallel_interface_arg, (unsigned long int)&thread, x);
+	    bu_log("ERROR: bu_parallel: pthread_create(0x0, 0x0, 0x%lx, 0x0, 0, %p) failed on processor %d\n",
+		   (unsigned long int)parallel_interface_arg, (void *)&thread, x);
 	    /* Not much to do, lump it */
 	} else {
 	    if (UNLIKELY(bu_debug & BU_DEBUG_PARALLEL)) {
 		bu_log("bu_parallel(): created thread: (thread: %p) (loop:%d) (nthreadc:%d)\n",
 		       (void*)thread, x, nthreadc);
-	    }
+		}
 
 	    thread_tbl[nthreadc] = thread;
 	    nthreadc++;
@@ -1078,13 +1102,15 @@
     /* Create the Win32 threads */
 
     for( int i = 0; i < ncpu; i++){
+		
 	hThreadArray[i] = CreateThread(
 	    NULL,
 	    0,
 	    (LPVOID)parallel_interface,
-	    NULL,
+	    &user_thread_data_bu[i],
 	    0,
 	    &dwThreadIdArray[i]);
+
 	if (hThreadArray[i] == NULL) {
 	    bu_log("bu_parallel(): Error in CreateThread");
 	    bu_exit();
