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
2
votes
1 answer

Segmentation fault (exit code 139) when using pthread_join

I'm doing some first steps with threads on Linux systems, and i have this error which occures on the base of a program that gets some n argument and creates n number of threads. Here is the important part of the code: The function the threads should…
argamanza
  • 1,122
  • 3
  • 14
  • 36
2
votes
2 answers

What if thread exit before other thread wait for it(join)?

For example, If I create 3 threads and join them in the same order. If the second thread exit first, then what would happen to the pthread_join. Will the program block until tid1 exits or directly return from pthread_join(&tid2,NULL)? pthread_t…
user5574376
  • 371
  • 1
  • 5
  • 12
2
votes
2 answers

Type-casting void* to long

Is it possible to directly type-caste a void pointer to long without causing a trouble? Below is a little code snippet I extracted from the code here (Example under Pthread Joining section of the page). { void *status; long t; rc =…
7_R3X
  • 3,904
  • 4
  • 25
  • 43
2
votes
1 answer

pthread_join(thread_id, &res) , if &res is not NULL - is free(res) needed?

I've stumbled across a code example here. The lines that caught my attention (all other lines skipped): { ... void *res; ... s = pthread_join(tinfo[tnum].thread_id, &res); ... free(res); /* Free memory allocated by thread */ } …
tum_
  • 632
  • 1
  • 7
  • 16
2
votes
1 answer

pthread_join always causes SIGSEGV

For some reason, pthread_join always causes a SIGSEGV action on my computer when I run with Valgrind. To test this, I ran the following code from https://computing.llnl.gov/tutorials/pthreads/: /* pthread.c */ #include #include…
ethanabrooks
  • 747
  • 8
  • 19
2
votes
1 answer

Call join child pthread in main function

I have the test code: #include #include #include pthread_t th_worker, th_worker2; void * worker2(void *data) { for(int i = 0; i< 1000000; i++){ printf("thread for worker2----%d\n", i); …
Thtam
  • 21
  • 1
  • 5
2
votes
3 answers

Assure the execution of every thread

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…
qwerty
  • 486
  • 1
  • 11
  • 37
2
votes
1 answer

Why does pthread_join() not create a deadlock?

Below is the program for which I am expecting the program to go into a deadlock because pthread_join() is a blocking wait on a thread (it is waiting to terminate). But I see that pthread_join() does not block and returns with failure (35 =…
overexchange
  • 15,768
  • 30
  • 152
  • 347
2
votes
2 answers

Multithreaded messages synchronization

I need to print 2 messages each one in each thread in C and synchronize them. The one thread prints One and the second prints Two. So my code is something like that void printOne(void* empty){ while(1) printf("One "); } void printTwo(void*…
2
votes
2 answers

Call pthread_create from outside main function

I want to do something like this: void *do_work_son(void *data) { mystruct *d = (mystruct*)data; while(true) { // d->whatever is corrupt } } void start_thread(pthread_t *mt) { mystruct data = ...; …
user67416
2
votes
1 answer

Android/Linux thread join with timeout

Is there a pthreads API call that can do something simlar to pthread_join() but with a timeout? I'm looking for a function that is similar to the Windows WaitForSingleObject(HANDLE handle, int timeout) function. I know that there's a…
Android Noob
  • 3,271
  • 4
  • 34
  • 60
2
votes
2 answers

Pthreads, confusion with pthread_join(pthread_t, void**)

I can't understand why does pthread_join takes as 2nd argument void** for the return value, whereas pthread_exit, which is given the return value, has the return value argument as void*.
Rampal Chaudhary
  • 707
  • 1
  • 8
  • 18
1
vote
1 answer

why pthread_join didn't block its calling thread

I am learning how to use , and the textbook says that: The pthread_join function blocks the calling thread ... But in my test, it didn't: void *a_thread(void *pt) { puts("a_thread:join"); pthread_join(*(pthread_t *)pt, NULL); // <--…
shynur
  • 334
  • 10
1
vote
1 answer

Segfault when passing pthread a function pointer that takes another function pointer as a parameter

I'm using bog-standard x86-64 Ubuntu gcc, and obviously there are no compile problems since I can get a segfault. I'm trying to create a pthread that invokes a function that takes another function based on some previously determined condition. That…
peads
  • 13
  • 1
  • 5
1
vote
0 answers

How to pass the argument 3 in pthread_create if we have a array and how to become returning values?Prime numbers check

I wanted to know how to get the result like: Number x is prime or Number x is not prime, sure this threaded ex. in 10 parts. How to pass argument 3 if we have an array and how the function checks an array if is prime or not? How can I do that?…
Artani
  • 81
  • 1
  • 6
1 2
3
17 18