FAQ Database Discussion Community


Why this simple program on shared variable does not scale? (no lock)

multithreading,concurrency,pthreads,concurrent-programming,pthread-join
I'm new to concurrent programming. I implement a CPU intensive work and measure how much speedup I could gain. However, I cannot get any speedup as I increase #threads. The program does the following task: There's a shared counter to count from 1 to 1000001. Each thread does the following...

pthread_join function in c

c,pthread-join
I have problem with pthread_join(), hope everyone answer. I am running the program below, and have one row to be printed out. After that, I am trying to delete "pthread_join(th,&val), and no row to be printed out. I found out all function in program, but i don't understand why. Can...

pthread_join Segmentation fault

c++,c,multithreading,pthread-join
I am trying to use pthread_join with this producer-consumer program but I keep getting a segmentantion fault. My purpose is to wait for all the producer threads to end and then terminate all the consumers. But after the first thread joins I get a segmentation fault. I searched the web...

Is it necessary to free the memory malloced for Pthreads?

pthreads,pthread-join
The code is as follows: pthread_t *threads; pthread_attr_t pta; threads = (pthread_t *) malloc(sizeof(pthread_t) * NumThreads); pthread_attr_init(&pta); for(i=0; i<NumThreads; i++) { pthread_create(&threads[i], &pta, (void*(*)(void*))Addup, (void*)(i+1)); } for(i=0; i<NumThreads; i++) { ret_count = pthread_join(threads[i], NULL); } pthread_attr_destroy(&pta); free(threads); // Is this needed? So, is it necessary to free(threads)? Does the pthread_attr_destroy(&pta)...

Assure the execution of every thread

c,multithreading,pthreads,posix,pthread-join
I want to run 4 different threads calling the same method, and I want to make sure that every single run comes from a different running thread. With the code provided bellow, the method function is ran the expected number of times but it is always done by the same...

pthread_join seems to modify my loop index

c,multithreading,for-loop,pthreads,pthread-join
My code (see below) produces an odd behaviour. The output is: Testing whether there are problems with concurrency ...rc is 0. i is 0 .rc is 0. i is 0 .rc is 3. i is 1 .rc is 0. i is 0 .rc is 3. i is 1 .rc is...

pthred_exit return variable static vs global scope

pthreads,static-variables,pthread-join
I am seeing different behaviors when variable used to get return values using pthread_join is defined gloabal vs static scope. I have included code_snippet here. Static variables int main() { static int r1,r2; pthread_t t1, t2; int i1[] = {1,2}; int i2[] = {3,4}; r1 = pthread_create( &t1, NULL, myfn,...