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

Why can't use ** to get return value of pthread_join

I used pthread_join function met a problem at yesterday,it's appear complie error, I have search it long time on net, but have no solve it. pthread_join.c: #include #include void* say_hello(void* args) { printf("hello…
Marcos
  • 111
  • 1
  • 2
  • 5
1
vote
3 answers

Create threads without pthread_join in C

In this segment of code, how can I create those threads without the use of the function pthread_join()? Using pthread_exit() didn't work. #include #include #include #include #include #include…
sh1ftz
  • 33
  • 1
  • 9
1
vote
1 answer

Pthreads - Can I detach from a thread and then join in main?

What I want to do is something on lines of... pthread_create(&producer_thread, &to_join, producer_routine, &queue); pthread_detach(producer_thread); ... ... pthread_join(producer_thread, NULL); Is this possible in some way, on running the above…
ashfaq
  • 77
  • 1
  • 9
1
vote
1 answer

Integrating pthread_create() and pthread_join() in the same loop

I am new to multi-threaded programming and I am following this tutorial. In the tutorial, there is a simple example showing how to use pthread_create() and pthread_join(). My question: why can we not put pthread_join() in the same loop as…
Sonu Mishra
  • 1,659
  • 4
  • 26
  • 45
1
vote
1 answer

Predict output of concurrent code

This is a question related to coursework that I got wrong earlier, and I cannot figure out why. The following code is given: int i = 0; void *doit(void *vargp) { i = i + 5; } int main() { pthread_t tid; ptr = &i; …
Naldhelaan
  • 390
  • 4
  • 13
1
vote
2 answers

Segmentation Fault during pthread_join()

I've got a program which has 10 Guest threads, 1 check-in thread, and 1 check-out thread. All threads are created using pthread_create() within my Main() method. The whole thing runs well until the end where the Main() method is supposed to…
Tawm
  • 535
  • 3
  • 12
  • 25
1
vote
1 answer

pthread lack of synchronization

I have the following code. This code is for a TFTP server that creates a fork or a thread for each request that is receives. My problem is in the thread methods. E.g I request 30 files from the server, is should creat 30 threads and give the…
rafaelcpalmeida
  • 874
  • 1
  • 9
  • 28
1
vote
0 answers

Using an array in a struct with pthread_join

I need some help with this. I am making a threaded factor program. Takes arguments from the command line, finds the prime factors and outputs them. However, my problem is that if I have multiple arguments being passed in (e.x. 20 15 10 5), all of my…
Desync
  • 11
  • 1
  • 2
1
vote
2 answers

Using pthread in simple C++ OpenCV project

I am trying to use pthread in my OpenCV Project. Intially I am simply trying to open two different images using two different threads. On Windows7 + VS2010 + pthreads-win32 lib, the program runs well. But on my Debian jessei machine (Opencv 2.4.1),…
kernelman
  • 992
  • 1
  • 13
  • 28
1
vote
1 answer

Calling pthread_join on a pthread_t which may not have been created

We have a class that has a protected pthread_t variable. Once that class has been constucted, the pthread_t exists, but it hasn't had an ID assigned to it which is what pthread_create does. Is it OK to call pthread_join on the pthread_t variable in…
Lieuwe
  • 1,734
  • 2
  • 27
  • 41
1
vote
0 answers

Segmentation Fault pthread_join because pthread_t id changed to 0

I am writing a C program with pthread. After I start my threads and execute them, something changes the value of one of my two pthreads to 0 in the background for a not explainable reason for me. On my machine, this problem already occurs between …
Mao
  • 56
  • 1
  • 6
1
vote
1 answer

pthread_join Segmentation fault

I am trying to use pthread_join with this producer-consumer program but I keep getting a segmentantion fault. My purpose is to wait for all the producer threads to end and then terminate all the consumers. But after the first thread joins I get a…
makripx
  • 35
  • 5
1
vote
1 answer

pthread_join seems to modify my loop index

My code (see below) produces an odd behaviour. The output is: Testing whether there are problems with concurrency ...rc is 0. i is 0 .rc is 0. i is 0 .rc is 3. i is 1 .rc is 0. i is 0 .rc is 3. i is 1 .rc is 3. i is 2 .rc is 0. i is 0 .rc is 3. i is…
Martze
  • 921
  • 13
  • 32
1
vote
2 answers

Is it necessary to free the memory malloced for Pthreads?

The code is as follows: pthread_t *threads; pthread_attr_t pta; threads = (pthread_t *) malloc(sizeof(pthread_t) * NumThreads); pthread_attr_init(&pta); for(i=0; i
mining
  • 3,557
  • 5
  • 39
  • 66
1
vote
1 answer

create Pthreads in loop

I create some threads in a for loop and after this loop, join them in other loop. they do their function till all of them finish it,do they? my last result is logically wrong . my result is correct, just when join each thread after create it!!
user3416282
  • 21
  • 1
  • 1
  • 9