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
59
votes
12 answers

Java Multithreading concept and join() method

I'm confused in join() method used in Threads in Java. In the following code: // Using join() to wait for threads to finish. class NewThread implements Runnable { String name; // name of thread Thread t; NewThread(String threadname) { …
user2696258
  • 1,159
  • 2
  • 14
  • 26
11
votes
5 answers

Do I need to join every thread in my application ?

I'm new with multi-threading and I need to get the whole idea about the "join" and do I need to join every thread in my application ?, and how does that work with multi-threading ?
Arwa196
  • 133
  • 1
  • 10
8
votes
2 answers

What if thread exits before calling pthread_join

I have a small code void *PrintHello(void *threadid) { cout<<"Hello"<
Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68
8
votes
1 answer

A detached pthread causes memory leaks

There is a known memory leak, when terminating a process with running undetached pthreads. However, detaching the thread doesn't seem to be a solution. Consider the following minimal example: #include #include static void*…
Witiko
  • 3,167
  • 3
  • 25
  • 43
5
votes
2 answers

when should I use 'lock' in multi-thread programing?

when should I use 'lock' in multi-thread programing? Just lock the area which each thread will modify or lock the area which each thread can access even it will not be modified ? struct share_data { /* share data */ thread_id; } thread 1…
Nick Dong
  • 3,638
  • 8
  • 47
  • 84
4
votes
3 answers

Why doesn't multithreading improve performance in this program for finding primes?

Running time is about the same, regardless of the number of threads. I am having trouble figuring out why. I know that the threads are running in parallel as they are supposed to, but I don't have even a good guess as to why there would be no…
amiller3513
  • 165
  • 1
  • 5
4
votes
2 answers

Why one can't do multiple pthread_joins on the same thread?

From https://computing.llnl.gov/tutorials/pthreads/: A joining thread can match one pthread_join() call. It is a logical error to attempt multiple joins on the same thread. Also from "man pthread_join": If multiple threads simultaneously try to…
SHH
  • 3,226
  • 1
  • 28
  • 41
4
votes
2 answers

Threads not running parallel

I want to make parallel threads. Example: my output is like: thread1 thread3 thread4 thread2... In main: pthread_t tid; int n=4; int i; for(i=n;i>0;i--){ if(pthread_create(&tid,NULL,thread_routine,&i)){ perror("ERROR"); } …
Nejc Galof
  • 2,538
  • 3
  • 31
  • 70
4
votes
3 answers

pthread_join() for asynchronous threads

I have written a simple demonstration program so that I can understand the pthread_join() function. I know how to use the pthread_condition_wait() function to allow asynchronous threading but I'm trying to understand how I can do similar work using…
Kyle Bridenstine
  • 6,055
  • 11
  • 62
  • 100
4
votes
2 answers

C - Creating n threads

I am working on the following function. This function should create n threads. Also it should print the tid of the child thread. But at the moment I am little bit confused. When I execute it and for example I create 5 threads, it returns all the…
user2965601
4
votes
5 answers

How do I get the error code from pthread_join()?

The following code fails to join pthreads and the message "join failed" is printed. How do I get more information about the failure and its cause? pthread_t aThread[MAX_LENGTH]; int errCode[MAX_LENGTH]; char returnVal; for(int i = 0; i <…
Celeritas
  • 14,489
  • 36
  • 113
  • 194
4
votes
3 answers

How to return a double value from pthread in c++?

After reading this thread: How to return a value from thread in C on how to return an integer value from a pthread I tested to see if it could work for a double, but it didn't. Is there a way to return a double, long or a string from the pthread…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
4
votes
1 answer

pthread Return Values to an Array

I am currently working on a project that uses pthreads. The project so far starts a user specified number of threads and does some work on each thread then closes. Each thread is stored in a dynamically allocated array of memory. I do this…
amura.cxg
  • 2,348
  • 3
  • 21
  • 44
3
votes
1 answer

How to manage properly pthread

I have some random issues sometimes to join pthread. I can just say that the thread is not stuck in a deadlock with a mutex when the join is failing. Most of the time the thread is idle (sleep syscall) when the timeout occurred on join. My need is…
ArthurLambert
  • 749
  • 1
  • 7
  • 30
3
votes
1 answer

What is the problem for PTHREAD_CANCELED and thread’s start function return value

I'm reading Kerrisk's book and see that the following as a note, Caution is required when using a cast integer as the return value of a thread’s start function. The reason for this is that PTHREAD_CANCELED, the value returned when a thread is…
1
2 3
17 18