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

Pthread in C basic print

I'm writing a C program using Pthreads that creates a child thread. After creating the child thread, the parent thread should ouput two messages: "parent:begin" then it should print "parent:done". Same for child thread "child:begin" and…
Le Coder
  • 79
  • 1
  • 7
0
votes
1 answer

Confused about the argument in pthread_create()

My question :why not just pass &i as the last argument to pthread_create()? instead he create a array to hold the same thing.... #define THREAD_CT 2 /* bump this up a few numbers if you like */ void *print_stuff(void *ptr) { int i, id= *…
overloading
  • 145
  • 9
0
votes
1 answer

How to cancel a pthread without cancellation point

I use a 3rd-party-library (dcerpc) for my application being a rpc server. Let's say the 3rd party function are in the namespace third. I call third::listen in a thread, in order to listen for incoming requests. "Third" provides all the mechanisms to…
Nico
  • 309
  • 1
  • 13
0
votes
1 answer

Whats the difference between pthread_join and pthread_mutex_lock?

The following code is taken from this site and it shows how to use mutexes. It implements both pthread_join and pthread_mutex_lock: #include #include #include void *functionC(); pthread_mutex_t mutex1 =…
Qandeel Abbassi
  • 999
  • 7
  • 31
0
votes
1 answer

Safe Programming of Pthreads on PIN-Using Simulators

I'm using an hardware simulator which uses PIN Tools to execute the workload. As the workload, I'm using the following code. Although it works on Ubuntu with -lpthread flag, it freezes on the simulator when it comes to join threads. I think there…
0
votes
4 answers

How does a thread know that there is a join method ahead

Below is my sample code, when my a.start() called it should create a thread and print "Run" immediately. But why does is called after printing "begin" 20 times. How does thread "a" decide that it doesn't have to call run() immediately. public class…
RaT
  • 1,134
  • 3
  • 12
  • 28
0
votes
3 answers

Multithreaded program goes in segmentation fault because of an argument

I'm having and odd problem with a multithreaded program of wich I will report only part of the code. When I try to run it I receive a segmentation fault error. Using gdb and valingrind I was able to find out that the problem is when I try to…
IXion
  • 11
  • 2
0
votes
1 answer

Wrong exit value from pthread_exit

Below code simply creates two threads and tries to get return values of them. I've compiled and run it on a 32-bit glibc-2.15 system and all went right (output: r1: 1, r2: 2). However when I did same thing on a 64-bit glibc-2.17 system, output was…
Ricardo Cristian Ramirez
  • 1,194
  • 3
  • 20
  • 42
0
votes
1 answer

pthred_exit return variable static vs global scope

I am seeing different behaviors when variable used to get return values using pthread_join is defined gloabal vs static scope. I have included code_snippet here. Static variables int main() { static int r1,r2; pthread_t t1, t2; int i1[] =…
night_hawk
  • 101
  • 1
  • 6
0
votes
1 answer

thread : pthread_cond_signal() not giving control to another thread on waiting condition

extern "C" { #include } #include using namespace std; pthread_mutex_t mutex_var = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond_var= PTHREAD_COND_INITIALIZER; int A; void * read_input(void* a) { int t; …
0
votes
1 answer

Why this simple program on shared variable does not scale? (no lock)

I'm new to concurrent programming. I implement a CPU intensive work and measure how much speedup I could gain. However, I cannot get any speedup as I increase #threads. The program does the following task: There's a shared counter to count from 1…
0
votes
1 answer

segmentation fault on joining pthread

I am trying to implement a thread interface class I am having a problem with join() function, it gives me a segmentation fault the output: g++ threadInterface.cpp -lpthread [murtraja@localhost src]$ ./a.out Name: Thread # 0 Policy: FIFO Scope:…
Murtaza Raja
  • 309
  • 4
  • 15
0
votes
2 answers

Why pthread_exit acts like pthread_join?

Code: void *PrintHello(void *threadid) { cout<<"Hello"<
Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68
0
votes
1 answer

PThread - Thread Exiting early despite calling pthread_join

I have implemented PThreads in a fairly elementary way as: #include #include #include using namespace std; class ThreadParameter { public: char symbol_char; int count; }; void* print_char (void*…
Failed Scientist
  • 1,977
  • 3
  • 29
  • 48
0
votes
0 answers

What are the possible return values of pthread_join when using pthread_cancel

The following code shows that I try to cancel the thread when the start_routine is not completed within the time ts, and join the thread to make sure the thread to terminate. I have used this on a simple function for start_routine and res2 returns…
chesschi
  • 666
  • 1
  • 8
  • 36