a71 Subj : Why it doesn't work ?? To : comp.programming.threads From : tarkan2097 Date : Tue Oct 04 2005 04:46 am Hi Everybody. I'm trying to develop a small program to run multiple SHELL scripts in parallel using threads. The problem is that I don't see the function executed by the threads. Can someone help me to debug this. I'm getting fustrated now. Thanks a lot. I can provide the complete code (.c .h makefile..) if required. Hereafter is an excerpt of the code: // Pool structure typedef struct tpool { pthread_t *threads; int cur_queue_size; task_p queue_head; } tpool; typedef tpool * tpool_p; /**************************************/ /* Initialization of the pool */ /**************************************/ void tpool_init(tpool_p mytpool, int max_num_worker, int nb_scr_2_exec, task_p tsklist) { tpool_p tpool; int num_worker_threads = max_num_worker; int i, rtn; if(DEBUG) printf("Entering tpool_init function\n"); // Initializing the pool and allocating the data structure if ((tpool = (tpool_p) malloc(sizeof(struct tpool))) == NULL) perror("malloc"), exit(1); // If number of task to run < max number of thread, allocate just the required number of thread if(nb_scr_2_exec < max_num_worker) num_worker_threads = nb_scr_2_exec; // Initialize the fields if ((tpool->threads = (pthread_t *) malloc(sizeof(pthread_t) * num_worker_threads)) == NULL) perror("malloc"), exit(1); tpool->cur_queue_size = nb_scr_2_exec; tpool->queue_head = tsklist; for(i=0; i< num_worker_threads; i++) { if(DEBUG) printf("Giving job to thread %d\n", i+1); //if((rtn = pthread_create(&(tpool->threads[i]), NULL, tpool_thread, (void *)tpool)) != 0) if((rtn = pthread_create(&(tpool->threads[i]), NULL, tpool_thread, NULL)) != 0) printf("pthread_create ERROR %d\n", rtn); if(DEBUG) printf("pthread_create returns %d\n", rtn); } mytpool = tpool; if(DEBUG) printf("End of tpool_init function\n"); } void *tpool_thread(void *arg) { //tpool_p tpool = (tpool_p)arg; //int rtn; //char script[100]; printf("In the tpool_thread function\n"); if(DEBUG) printf("Running tpool_thread function\n"); //sleep(10); /*while(tpool->cur_queue_size != 0) { if((rtn = pthread_mutex_lock(&queue_lock)) != 0) printf("pthread mutex lock error %d", rtn), exit(1); printf("Will run script now...\n"); // Dequeue the next item //strcpy(script, } */ return 0; } . 0