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's the detail about gdb, does it hold one thread?

What's the detail about gdb, does it hold one thread when debugging code? I set an exit flag in the main thread, and I have joined other threads before printing the flag. When I run the debug version using gdb after compiling with argument "-g", it…
Nick Dong
  • 3,638
  • 8
  • 47
  • 84
0
votes
1 answer

pthread input thread and worker thread synchronization

I have two pthreads one of them is reading from cin and putting it in a QUEUE and the other one is a worker thread checking the QUEUE every 2 seconds and printing something if there is something in it. This is what's in my main: #include…
mrBorna
  • 1,757
  • 16
  • 16
-1
votes
1 answer

How to prevent memory leaks in pthreads?

How to prevent memory leaks in pthread? I am running a server client program where server has to execute a pthread program and pss the result to client. The client keeps asking for the command again and again until it is stopped. The result provided…
-1
votes
2 answers

My C code does not work but another example, something similar to me, works. Why?

My code is not working... But another example that is similar to my code is working. How can I fix? It seems like pthread_join() is internally change integer value like my code. But mine does not work. Can anybody help me to fix? #include…
-1
votes
1 answer

Two consecutive calls to pthread_join(). Should the second call not even start until the first thread terminates?

Here is the code (adapted from www.cs.cmu.edu): #include #include #include void *print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Thread 1"; char…
asinix
  • 966
  • 1
  • 9
  • 22
-1
votes
1 answer

What is the Purpose of argument in pthread_exit?

basically, I am trying to understand the real purpose of pthread_exit. As you can see, there are multiple pthread_exit code I have tried. And Following are the result i observe : - Exit 1: 42 - Exit 2: 42 - Exit 3: thread failed - Exit 4:…
Cliff
  • 140
  • 1
  • 8
-1
votes
2 answers

Thread not working as intended

I am pretty confuse why my program is not working as intended. I have three similar function: static void *L1(void *ptr ) { char *text = (char *)ptr; int ret; int fd = open("/dev/L1", O_RDWR); ret = write(fd, text, strlen(Send));…
D.Bryan
  • 19
  • 6
-1
votes
1 answer

Why is the return value of pthread_join() not changing with each call to pthread_join()

This program works fine if the user enters only 1 number on the command line. It will factor out the prime factors and output them to the console just fine. J_10542741@cs3060:~/assn3$ ./assn3 12 12: 2, 2, 3, My problem is when I test it on these…
-1
votes
2 answers

pthread wait other threads to finish

How to create threads only when previous threads are finished? main { create thread1 & thread2 wait for thread1 & thread2 to finish create thread3 & thread4 }
JR Galia
  • 17,229
  • 19
  • 92
  • 144
-1
votes
2 answers

Error at pthread_join

My program needs to create some threads, but I'm stuck at pthread_join, as it always goes into the error case, because the return ( safe ) is 3, instead of 0, which I assume is the correct number in case everything goes okay. Edit: To better explain…
TJacob
  • 123
  • 1
  • 3
  • 10
-2
votes
1 answer

Segmentation fault (core dumped) at pthread_join

I'm trying to run this file but it gives out this fault. Getting a segmentation fault (core dumped). Segmentation fault (core dumped) at pthread_join . Tried running printf at all the places and felt that this must be the error. #include…
-2
votes
1 answer

glibc pthread_join crash when call pthread_join() twice

I have written the following code using the POSIX pthread library: #include #include void *thread_function(void *arg) { char *code = "1"; } int main() { int res; pthread_t a_thread; void *thread_result; res =…
PJ.Jing
  • 11
  • 3
-2
votes
3 answers

The output of the following program

When I run the following program, the output is 5. Why 5? Why not 8? void *doit(void *vargp) { int i = 3; int *ptr = (int*)vargp; (*ptr)++; } int main() { int i = 0; pthread_t tid; pthread_create(&tid, NULL, doit,…
sadsadas
  • 1
  • 1
-2
votes
1 answer

After thread join an array inside a struct was destroyed in C

I'm trying to use memcpy to gather an array inside a struct to an array in the global scope. I checked my code, and I can verify that the size I allocate to each array is correct and identical. I can confirm that my problem is with mythrD.sample,but…
RandomEli
  • 1,527
  • 5
  • 30
  • 53
-2
votes
1 answer

Why is pthread_join() never called?

I am quite inexperienced with multithreading in C, so I would really appreciate some input on this piece of client-side code (extraneous parts have been stripped out for simplicity's sake). // client_read(): read from server void *client_read(int…
AK-33
  • 167
  • 2
  • 10
1 2 3
17
18