Hi, I have this code:
This program are reading data from file. It must using threads. Every thread print part of file content. But these threads are running in sequence. First thread ends and second starts, when second ends third starts and so on. Why this threads are not running together? I know that pthread_join must wait while thread return a value and end but that is the reason why I use array of threads.Code:int thread_count = 5; pthread_t *thread; thread = malloc(thread_count * sizeof(pthread_t)); for ( i=0; i<thread_count; i++ ) { pthread_create(&thread[i], NULL, &count_character, (void*) f); pthread_join(thread[i], (void*) &result); }
I cannot use thread like pthread_t thread01, thread02, .... , but dynamically, because number of threads is argument of my program (in my example above is used 5 threads for example).
So what should I do to run threads together? How to create a dynamic array of threads?
Thanks