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
0
votes
0 answers

C posix pthread_create two threads ,but they can not support cross operation very well

General Question: I can't understand the mechanism of POSIX threads in Linux. Some specific questions would be asked under the code block. Description: I call two sub-threads in my main thread. One is Producer, the other is Consumer. But my program…
Victor
  • 23
  • 4
0
votes
1 answer

How do I stop threads stalling on pthread_join?

I've got a project where I'm adding jobs to a queue and I have multiple threads taking jobs, and calculating their own independent results. My program handles the SIGINT signal and I'm attempting to join the threads to add up the results, print to…
0
votes
2 answers

filenames not passing into pthread_create

Here are two problems in the program First, is that when I uncomment the pthread_join() in the main function, there will be a seg fault, other wise the program will run... Second, is that the output file will be missing the first letter of each word…
Jimmy Li
  • 53
  • 2
  • 9
0
votes
1 answer

·Wait for first of various threads in C

I have something like a list of things to calculate, and they are somewhat dependent on eachother (some of those calculations, may show that other calculations on the list are not needed). Also I want to calculate always two of them at a time (two…
0
votes
1 answer

What is wrong with the below code ? Expected X modified by thread Func 1 followed by X modified by thread Func 2

While studying multithreading, I wrote following code but no output observed on screen. What am I doing wrong here ? I expected output as follows: X modified by threadFunc 1 X modified by threadFunc 2 but nothing is seen on the screen, and the…
Trickmaster
  • 187
  • 2
  • 5
0
votes
2 answers

using pthread with memory leak

Just a small program to test multi-threading. It supposed to print out a 'Hello' message with the index of the thread and the thread location. I read why pthread cause memory leak and tried to use pthread_join. It seems that the memory leak still…
gjjhhh_
  • 169
  • 3
  • 21
0
votes
2 answers

How to join with whichever thread finishes first?

The main thread spawns > 1 threads, and each of them can call return with an error value. If this happens, it is meaningless for the other threads to continue, and so they should be canceled. So, I want my main thread to: Join with whichever thread…
user4385532
0
votes
2 answers

unexpected result when type casting the return value from pthread in C

I was practicing pthread in C, try to work out a function that distribute the workload as equally as possible among the threads. Each thread returns a integer representing the amount of work they were assigned. #include #include…
Xiaowen Hu
  • 41
  • 1
  • 5
0
votes
1 answer

pthread_join error code 3

i have problem in my project. it throws me error code 3. I just add part of my code to let you see what I did. in main.cpp I declared on the threads then I send to initRequestThreads(in thread.h) to create the threads. then in main.cpp i let the…
Manspof
  • 598
  • 26
  • 81
  • 173
0
votes
1 answer

Allocate shared memory based on thread computations

In a multi-threaded program I need to allocate shared memory based on the estimate computed in parallel by threads and then use that shared memory across all threads (after synchronization). Is there a way to do so without joining the threads and…
bawejakunal
  • 1,678
  • 2
  • 25
  • 54
0
votes
1 answer

Trying to understand how pthread works in C

I am trying to use pthread in C to compare two strings. The idea is to see if the complete string 2 is in string 1 (For Example, if string1 = lkajdsgl and string2 = jd then I would have one match). What I don't understand is how the pthread works in…
Joseph
  • 301
  • 3
  • 13
0
votes
2 answers

Segmentation fault (core dumped) after pthread_join

I am trying to work with multi-threaded programs, and I am getting an error with the pthread_join function. The output from this code is: after pthread_create Segmentation fault (core dumped) And here is the code: #include #include…
0
votes
1 answer

Pthread_join Printf

I have this problem that I'm studying but I'm not understanding one part. The script is not in English so translating would be pretty tedious but the basic problem is to make a thread read a specific text file and find a specific word. Each file has…
0
votes
1 answer

How to query several pthreads (children) to know which one(s) terminated

I have several pthread children created through pthread_create and marked as joinable. I may wait for them one after another using pthread_join, but, I would like to wait for joining anyone (i.e. as soon as any one of them ends). How do I know…
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
0
votes
1 answer

pthread join child thread in both thread function and cancellation handler?

I got the following scenario with a concurrency problem, implemented using pthread library: I got a thread that might be cancelled at any time. When that thread is cancelled, it needs to cancel its child thread, and make sure its child thread is…
A.Stone
  • 137
  • 1
  • 9