

Some older compiler versions complain about "threads" being declared in the
middle of main(), so this patch makes "threads" a pointer and allocates it
using malloc() after we know the number of threads we're going to run.

Thanks to Ron Burkey for noticing this and letting me know.



---

 cur-root/main.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff -puN main.c~malloc_threads main.c
--- cur/main.c~malloc_threads	2004-04-20 18:40:54.000000000 -0300
+++ cur-root/main.c	2004-04-20 18:44:14.000000000 -0300
@@ -24,6 +24,7 @@ int main(int argc, char **argv)
 {
 	int i, nthreads;
 	pid_t pid;
+	pthread_t *threads;
 
 	/* parse the command line, we only have one optional parameter to tell
 	 * the number of processing threads */
@@ -72,11 +73,11 @@ int main(int argc, char **argv)
 	}
 	
 	/* create the threads */
-	pthread_t threads[nthreads];
+	threads = malloc(nthreads * sizeof(pthread_t));
 	for (i = 0; i < nthreads; i++) {
 		/* we pass the thread number as the parameter pointer, which
 		 * is used to index several arrays inside net.c */
-		pthread_create(&threads[i], NULL, &net_proc_loop, (void *) &i);
+		pthread_create(threads + i, NULL, &net_proc_loop, (void *) &i);
 	}
 
 	/* main select loop */
@@ -84,7 +85,7 @@ int main(int argc, char **argv)
 	
 	/* wait for threads to complete */
 	for (i = 0; i < nthreads; i++) {
-		pthread_join(threads[i], NULL);
+		pthread_join(*(threads + i), NULL);
 	}
 	
 	return 0;

_
