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

What is the pthread's join prerequisite

With pthread, we cannot join any thread. What is the prerequisite and why is it there? According to : https://man7.org/linux/man-pages/man3/pthread_join.3.html The pthread_join() function waits for the thread specified by thread to terminate. If…
wazowski
  • 115
  • 8
0
votes
0 answers

how do I pass a variables value into the pthread create parameters using a void function?

I'm doing a monte Carlo simulation to calculate pi using threads, I believe the mass of my logic is correct. I just need to pass the correct value into the pthread create function under the C library i'm using, I just don't understand how fulfill…
0
votes
0 answers

Can you get the return value of a thread if it exited before you call join?

If you have a thread A which calls pthread_exit(return_val) before thread B can call pthread_join(A, ret_val_A), what is the outcome? Does join return as if the thread did not exist? Clarification: Im not asking if you can join once a thread has…
beans
  • 31
  • 5
0
votes
1 answer

When does pthread_timedjoin_np() return EBUSY?

I am trying to handle all the possible return values of pthread_timedjoin_np(), but I did not quite understand, when does it return EBUSY? If the thread returns within the given time pthread_timedjoin_np() always returns zero, while if time has…
madmurphy
  • 1,451
  • 11
  • 20
0
votes
1 answer

Threads appear to run randomly.. Reliable only after slowing down the join after thread creation

I am observing strange behavior using pthreads. Note the following code - #include #include #include #include #include #include typedef struct _FOO_{ int ii=0; std::string…
Rajat Mitra
  • 167
  • 1
  • 11
0
votes
0 answers

Cython: How to wait for all threads in prange to be all done?

In pure Python (threads co-exist but not parallel), all threads can be waited to be all done by using join method: ts = [] # Threads for i in range(10): ts.append(Thread(func=...)) ts[-1].start() for i in range(len(ts)): ts[i].join() #…
Dee
  • 7,455
  • 6
  • 36
  • 70
0
votes
1 answer

Kill either thread and exit process

I am creating two threads that run independently. When there is an error in one of the threads, I return from that particular thread with return value -1. But I want to kill the other thread and gracefully terminate/ exit the process. How do I…
bvj0412
  • 17
  • 5
0
votes
2 answers

Trouble calling function via pthread

I have a function that counts the number of occurences of a string in a char array. Calling this function normally with findword(copy, "polar") works perfectly fine and prints an int that's the number of times the string "polar" occurs in the char…
kikikey
  • 105
  • 1
  • 8
0
votes
1 answer

"pthread_join" doesn't return on a just cancelled thread (with "pthread_cancel")

I have a pool of threads (QueueWorkers class) in my program that are released using this logic: int QueueWorkers::stop() { for (unsigned int ix = 0; ix < threadIds.size(); ++ix) { pthread_cancel(threadIds[ix]); …
fgalan
  • 11,732
  • 9
  • 46
  • 89
0
votes
1 answer

Using pthread_join() on multiple threads giving unexpected behavior

I am learning how to use threads in C and have run into a problem when creating the threads. I am making a program that takes in 2 or more file names as command line arguments, counts the number of bytes in each file in their own thread, and then…
0
votes
1 answer

Functionality of pthread_join() in Ubuntu C

Working on a small C code with pthread library. My requirement for this code is to first deposit money then withdraw money. #include #include int counter = 0; void *increase(); void *decrease(); int balance = 500; void…
sam
  • 11
  • 2
0
votes
1 answer

pthread_exit() and pthread_join() don't work

I don't know why it doesn't return the value that I type in. I know it's not the void* arg because it prints the right number, but I don't have any idea. CODE: #include #include #include #include #include…
0
votes
1 answer

Calling pthread_join with one argument causes a segmentation fault?

If I call pthread_join continuously (without using other functions) it will cause a segmentation fault. I can solve the problem by inserting a sleep(); , printf() or anything else between two calls of pthread_join. OS & GCC Version: gcc…
omar.zhou
  • 23
  • 1
  • 7
0
votes
2 answers

Multi threading Raytracer

I am making a raytracer, im trying to use pthread to divide the rendering. i noticed that isnt helping with the speed because the function pthread_join is to slow, if i use a loop to make the 'await' is way faster and works almost every time fine.…
0
votes
1 answer

pthread getting crashed in C

I am trying multithreading in my C project, using pthread. I was playing with this code but it is getting crashed and don't know why. #include #include int g = 0; void *myThreadFun(void *vargp) { int *myid = (int…
Ayan Bhunia
  • 479
  • 3
  • 14