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
3
votes
2 answers

Merge Sort with PThreads in C

Side Note: I'm beginning to learn how to use pthreads and I'm starting to get the concept. I've been using this example script (written in C++) here to manage a Merge Sort with threads:…
theflarenet
  • 642
  • 2
  • 13
  • 27
3
votes
2 answers

how to check if a pthread is joinable?

I know I can create a pthread with joinable attribute set, but once created, am I right that I can also change that pthread to a detached pthread? If that's the case, how can I check if a pthread is joinable? And how can I change a pthread from…
james
  • 1,107
  • 14
  • 29
3
votes
1 answer

What happens when pthread_join is commented?

#include #include "mythreads.h" #include #include void * mythread(void *arg) { printf("%s\n", (char *) arg); return NULL; } int main(int argc, char *argv[]) { if (argc != 1) { fprintf(stderr,…
FlyingAura
  • 1,541
  • 5
  • 26
  • 41
3
votes
1 answer

pthread_join does not affect main thread

I have found this Sockets tutorial http://www.binarytides.com/socket-programming-c-linux-tutorial/ and I am having trouble with the last example. It is a threaded server using sockets and pthreads. The code compiles fine but it does not work as…
user1359448
  • 1,539
  • 3
  • 14
  • 23
3
votes
1 answer

Multithreading in multi cpu multithreading

Suppose I have an undirected graph. A small portion of the graph : A -----\ C B -----/ Now the node A and B proceeds to modify parallely node C. // Node A and Node B process Node C in parallel thread. I want the thread for Node B will wait…
3
votes
2 answers

Destroy a detached thread (POSIX)

I was just wondering, if I create a detached thread (POSIX) using an attribute and the function "pthread_attr_setdetachstate" with the argument PTHREAD_CREATE_DETACHED, do I have to destroy the thread at the end of my program ? I know that I have to…
Dust009
  • 315
  • 2
  • 10
3
votes
2 answers

Segmentation Fault at pthread_join

So when I run my code, I'm getting a segmentation fault right at the pthread_join. There is a print statement after my pthread_join that doesn't run. Does anyone have any idea why? Could you give me some hints or ideas as to how to figure this…
angyxpoo
  • 193
  • 2
  • 5
  • 16
3
votes
2 answers

How to join threads created dynamically in c/c++

I have written a C/C++ code which implements socket connection and the main thread is in continuous loop listening at its port. When a connection request comes at this port, I have spawned a thread using pthread calls and offloaded the work on this…
Yogesh lele
  • 392
  • 4
  • 17
3
votes
2 answers

pthread: join a detached thread doesn't set errno correctly

I am checking the behavior of 'pthread_join' and have the following code: #include #include #include #include #include void *thread(void *vargp) { pthread_detach(pthread_self()); …
chuchao333
  • 1,438
  • 1
  • 14
  • 22
3
votes
1 answer

C pthread join an ended thread

I'm building 2 programs (client/server) that communicate through FIFOs. Both programs have threads. When the Client's thread ends it doesn't get joined, and main hangs. The programs do the following: Server: main: reads from FIFO1 main: create…
CiberWizZ
  • 45
  • 5
2
votes
0 answers

What could delay pthread_join() after threads have exited successfully?

My main thread creates 8 worker threads (on a machine with a 4 core, 8 thread CPU), and then waits for them to complete with pthread_join(). The threads all exit successfully, and the pthread_join() successfully completes. However, I log the times…
2
votes
4 answers

Why is retval a void** in pthread_join?

I am having a hard time understanding why pthread_join's retval argument is a void**. I have read the manpage and tried to wrap my head around it but I still cannot fully understand it. I couldn't convince myself that retval cannot be a void*. Could…
lumapools
  • 64
  • 6
2
votes
0 answers

It seems that pthread_join() is not invoked or PTHREAD_ATTR_FLAG_DETACHED is not set Flutter Firebase

I've followed a tutorial regarding 'Flutter Firebase Authentication. I faced many issues due to it being in an old version of firebase, but I migrated and fixed all problems related to the null safety and others. It showed 0 problems/errors. But on…
Nadia Nadou
  • 137
  • 2
  • 7
2
votes
1 answer

Code of the function pthread_join - Pthread Library

I'm looking for the code of the pthread_join, but online I found only the prototype. Could you tell me where I can find it please?
Gennaro Arguzzi
  • 769
  • 1
  • 14
  • 27
2
votes
2 answers

Logic problem in C. Define number of interactions on pthreads

So i have these code, i want to define my number of interactions manualy, so for each thread basicaly i define lets say 10 interactios so each thread will compute a block of 10. If i do that the thread wont go after the first 10. Basically what i…
1
2
3
17 18