Questions tagged [pthread-join]

The `pthread_join()` function is part of pthread.h used to wait for another thread to finish executing.

A call to pthread_join(t, ...) suspends execution of the caller's thread. It does not return until thread t has finished executing.

Linux Man page

257 questions
1
vote
2 answers

How to stop a blocking pthread_join() implemented in a shared library

My code is calling a function from a third-party library before the exit of the program. Unfortunately the called function blocks the main thread, which is caused by pthread_join() in the .so library. Since it is inside the library, which is out of…
lichgo
  • 523
  • 1
  • 6
  • 16
1
vote
1 answer

Question about pthread and multithreading

So I created a program that calculates matrix multiplication sequentially then records the time, then calculates matrix multiplication using any number of pthreads entered in the command line numberOfThreads. But regardless of how many threads I…
Reed Sager
  • 25
  • 3
1
vote
1 answer

What will happen if the pthreadId is zero in pthread_join(pthreadId, NULL) on Android?

What will happen if the pthreadId is zero in pthread_join(pthreadId, NULL) on Android ? Like the following code snippet: pthread_join(0, NNULL);
Jerikc XIONG
  • 3,517
  • 5
  • 42
  • 71
1
vote
1 answer

c - can't understand pthread_join()

I can not figure out where I'm wrong, after running the code arrived in the for where it runs the pthread_join() , many pthread_join() return with value 3 instead of 0. Furthermore, printing the value of i is not always consistent and this causes…
JayJona
  • 469
  • 1
  • 16
  • 41
1
vote
0 answers

multithread call by pthreads, different result while sorting

In the following I'm trying to sort an array with multiple threads using pthreads. The idea is to split the array and give each thread one part. shell_sort does it in serial while in my parallel try I call it by each thread. The multithread version…
KcFnMi
  • 5,516
  • 10
  • 62
  • 136
1
vote
1 answer

POSIX pthread_join hangs after thousands of threads

I am new to POSIX and I cant find a solution to this particular problem. Are there any known issues with creating pthreads inside of loop with big number of iterations(>100000)? It seems like every time I execute, it hangs on a random…
Edward Ep
  • 33
  • 6
1
vote
1 answer

Python threading: Is there a way to detect a join() call in a thread?

I have created a program that runs X number of threads which all need to be able to be closed down by the main thread. Currently I can stop the program so that each thread will be abruptly killed. I want to be able to detect the close and handle it…
Frederik Petersen
  • 1,025
  • 3
  • 16
  • 30
1
vote
1 answer

Sorting 2 arrays using 2 threads takes more time than sorting the 2 arrays one by one

I have 2 unsorted arrays and 2 copies of these arrays. I am using two different threads to sort two arrays, then I am sorting other two unsorted array one by one. What I thought was that the thread process would be faster but it's not, so how does…
1
vote
1 answer

Value of the variable passed as reference gets changed in threads

I wrote this small program for understanding pthread_create and pthread_join but I dont understand why the value of the variable data gets altered after thread_join. Its printed as 0 after the call to pthread functions. #include #include…
Karthick
  • 1,010
  • 1
  • 8
  • 24
1
vote
1 answer

Solaris thr_join vs posix pthread_join

In Solaris, thr_join documentation states the following: int thr_join(thread_t thread, thread_t *departed, void **status); If the target thread ID is 0, thr_join() finds and returns the status of a terminated undetached thread in…
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
1
vote
2 answers

Using pthread to print 2-d array

So i have an assignment that says I have create a 2-d array[5][12] with random values between 1-99. Then using pthreads, I have to either add 1 or subtract 1 to each element in the array and then print the results and divide the process into either…
1
vote
2 answers

pthread_join error, making threads from threads

I am currently trying to make threads from other threads. When my threads are trying to join, I get a segfault This is my main function: int main( int argc, char *argv[] ) { std::cout<< "start" << std::endl; init(); std::cout<<"finished…
1
vote
1 answer

passing for loop index into pthread_create argument object in C

I would like to pass my for loop's index into the pthread_create's argument through a wrapper object. However, the printed integer from the thread is incorrect. I expected the below code to print out, in no particular order. id is 0, id is 1, id is…
GucciProgrammer
  • 181
  • 2
  • 4
  • 13
1
vote
1 answer

Parallel programming using Pthreads

I am new in the domain of parallel programming so I decided to fiddle around with the pthread_join() sub routine. I came up with the following code to compute a*X + Y where a is a scalar and X, Y are vectors of some size. Here is what I have written…
Abhijeet Mohanty
  • 334
  • 1
  • 6
  • 21
1
vote
2 answers

Change order in pthread_join will return segmentation fault on Linux

Can you explain why in Linux (not in Mac) I get Segmentation Fault when I do: pthread_join(thread2, (void**)&status); pthread_join(thread1, (void**)&status); But is ok when I do: pthread_join(thread1, (void**)&status); pthread_join(thread2,…
Giovanni
  • 79
  • 8