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

pthread_join function in c

I have problem with pthread_join(), hope everyone answer. I am running the program below, and have one row to be printed out. After that, I am trying to delete "pthread_join(th,&val), and no row to be printed out. I found out all function in…
Hoang
  • 55
  • 1
  • 2
  • 10
0
votes
1 answer

How to wait two pthreads?

Would any one please tell me what happens between the last two code lines // Creating Server and Client threads pthread_create(&serverThread, NULL, (void* (*)(void*))&Server,(void *)0); pthread_create(&clientThread, NULL, (void*…
0
votes
1 answer

Creating a new thread each time a method is called using pthread

I want to create a program that creates a new thread each time a specific method is called. Here is my working code so far: #define NUMBER_OF_THREADS 3 pthread_t threads[NUMBER_OF_THREADS]; pthread_attr_t attr; void *BusyWork(void *t) { int…
Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231
0
votes
0 answers

Segfault at pthread_join (only sometimes)

I want to use a bunch of pthreads in my application. To get familiar with the pthread library, I started with a small demo application (see attached sourcecode). If I create 200 threads, all works well. However, if I increase the number of threads…
user2494129
  • 717
  • 2
  • 13
  • 24
0
votes
2 answers

how to pass a thread parameter as a reference instead of by value?

#include #include #include #include const int kMaxThreads = 10; void * threadRoutine(void * threadArg) { int myThreadNumber = * ((int * ) threadArg); //(int)threadArg …
Joe
  • 1
  • 1
0
votes
1 answer

How to improve forking/joining of multithreading program?

apparenty the OP got their answer already, in the comments, and the issue is resolved now. I have coded a prime number program (sieve of eratosthenes) that executes using pthreads. This is my first multithreading program and I don't know why my…
kishoredbn
  • 2,007
  • 4
  • 28
  • 47
0
votes
1 answer

Using pthread_cond_t to signal end of execution

I am using pthread_cond_t to signal the end of execution of child threads to the main thread. Since I'm not synchronizing the access to a shared resource, I wonder what the loop embracing pthread_cond_wait would be? Here's what I…
NewToAndroid
  • 581
  • 7
  • 25
0
votes
1 answer

pthread_cond_wait not waked up correctly if not joined

The code below was taken from llnl tutorials on pthreads with two modifications: comment the sleep(1); in function comment the pthread_join(thread[i],NULL); in function…
altkatz
  • 107
  • 8
0
votes
1 answer

main() does not terminate after successful pthread_join

I have a program that starts a pthread and later on waits for the termination of this thread before it returns. The code is something like: int main(int32_t argc, char* argv[]) { pthread_t t; /* initialization and other stuff ... */ …
Bastian
  • 4,638
  • 6
  • 36
  • 55
0
votes
1 answer

exact need of using pthread_join() and pthread_exit()

There have been questions asked before on this topic , but still I'm not very clear with the usage of pthread_join(). I read somewhere that resources are not cleaned up when a thread exists without getting joined with the main thread . What are the…
Sumit Das
  • 1,007
  • 9
  • 17
0
votes
1 answer

Pthread Join in C?

I'm writing code to save text to a binary file, which includes a function to auto-save text to the binary file, as well as a function to print from the binary file, and I need to incorporate pthread locks and join. We were given pthread_mutext_t…
Madison Rubia
  • 19
  • 1
  • 3
0
votes
1 answer

How to call main thread in the child thread created by pthread_create?

I used pthread_create created a child thread for http requested,after i get the data i want to call the main thread to do some update of UI. pthread_detach(); pthread_exit(); pthread_join(); The three function which can use for that?Why? Is there…
Dracuuula
  • 313
  • 2
  • 15
0
votes
0 answers

Threading Issue while using JNI with CORBA

I have a Java application which is using JNI. Using Main thread of java I am creating a pthread eg. t1(using pthread_create) in native. I also have a UI which is interacting with my java application with IDL & CORBA. From UI when I call my Close()…
0
votes
1 answer

How would I know if the thread is a joinable thread ?

I'm new with multi-threading and I need to know when exactly do I need to join my thread not to detach it. what are the factors I need to take in consideration to know that the thread is "must to join" ?
Arwa196
  • 133
  • 1
  • 10
0
votes
1 answer

Not able to set processor affinity

I'm trying to implement this code on a 8 core cluster. It has 2 sockets each with 4 cores. I am trying to create 8 threads and set affinity using pthread_attr_setaffinity_np function. But when I look at my performance in VTunes , it shows me that…