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

Multithreading and pthread_join

My program reads in maze from a text file, then the main program creates 3 different threads to delve into this maze and search for the exit. When a thread discovers the exit, it will post its solution path in the main thread. In this maze, there…
Jary Rym
  • 87
  • 2
  • 7
1
vote
0 answers

Calling pthread_exit in main thread after doing detach leaves it as defunct

I am trying to create a new thread, offload execution to the new thread and kill main thread. This is the sample program. #include #include void * main_thread(void * param) { while (1) { } } int main(int argc, char…
user1912491
  • 101
  • 6
1
vote
4 answers

pthread_exit issues returning struct

I have a struct typedef struct something_t { int a; int b; } VALUES; In my thread function I do VALUES values; values.a = 10; values.b = 11; pthread_exit((void*)&values); And I try to receive by doing VALUES values; pthread_join(thread,…
Quillion
  • 6,346
  • 11
  • 60
  • 97
1
vote
1 answer

Receiving values from multiple threads in C

#include #include #include #include #define SIZE 3 /***I'm trying to send name of each file in a thread and trying to receive their respective size in main *******/ void *doit(void *name) { int…
1
vote
1 answer

What signal might pthread_join() cause?

I had a an error condition in C++ that I cannot easily reproduce in my call to pthread_join() some signal was generated, I do not know which one, but my signal handler was called and for some reason did not print out the normal debug information on…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
0
votes
2 answers

C - Integrating pthread_join and pthread_create in for loop, thread_returnValue pointers problem

im new to multi-thread programming in C. I implemented a thread_create.c file for two thread with a race of chars in linux. But if i wanna do it with a #define n for generical multi-thread file there's some error with pointers There's the…
VuciuS
  • 11
  • 1
0
votes
1 answer

Joining multiple threads to one thread in C

Basically the main thread creates threads 1 2 3 4. And 1 2 3 have to wait for 4 to end and main waits for threads 1 2 3. The code is as follows: #include #include #include #include pthread_t id[4]; void…
0
votes
0 answers

Unable to join the thread on the right place

In my game there are two (relevant for this problem) threads (both are joinable), one is player and one is shot. When the thread player is created, the start routine function is called, in which the shot thread is created. In that function, there is…
Milan
  • 1
  • 2
0
votes
1 answer

Why calling pthread_join on a detached thread return 0 (success)?

When we detach a thread, it is not associated with calling thread anymore then why did the join call succeed with return value 0?? // C program to show thread functions #include #include #include #include…
0
votes
1 answer

Why the output goes wrong when using pthread_join?

I am still learning about threads and I was trying to solve this problem in my code, when I am putting the pthread_join(thread[i],NULL) outside the loop that is creating the threads it always gives me wrong output and Thread with ID = 0 will not…
0
votes
0 answers

Using struct for multiple arguments for pthread_create, but struct member pointer returns null(or seg. fault error) inside function for pthread_create

#include #include #include struct arg_struct{ char* arg1; char* arg2; }; void *find_substr_count(void *context){ char* newStr; struct arg_struct* arguments = context; newStr =…
0
votes
1 answer

what's the meaning of "(void *)2" in c code?

I recently read a book about how to write code in unix environment.There is an expample code making me very confused. The example code: #include "apue.h" #include void * thr_fn1(void *arg) { printf("thread 1 returning\n"); return…
JasonZhang
  • 68
  • 1
  • 10
0
votes
1 answer

How to make all threads (pthread) wait till rest of all other threads are running before starting its execution?

The main processes launches 4 threads. Now at this time all 4 threads will start execution immediately, but I want all the threads to wait till rest of all threads are also in running state. I remember using a semaphore to track the thread counts,…
0
votes
1 answer

How to implement and profile pthreads continuously created on the heap?

Introduction I have a program where child threads are created that I would like to profile with Valgrind memcheck. From the responses to a previous question I've asked, I will need to use joinable (rather than detached) threads in order to test and…
karobar
  • 1,250
  • 8
  • 30
  • 61
0
votes
1 answer

The work done by a thread (inside a child process) on a class object. When child exits the work done by thread on class object is deleted

I have a simple class with a variable (var1). The function of the class "changeVar" will be passed to pthread which will update the value. My question is when that thread is called inside a child and it updates the value after the child exits why…