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 does pthread_join crash (seg fault) at 306 Joins?

I'm playing around with creating a BUNCH of threads, just see learn a bit more about pthread. I've copied a program I found, and instead of making 1 thread, and joining it, it will create X threads, and join them. When I tried 100 threads…
1
vote
2 answers

C - Pthreads threads go into infinite loop unless I print the output in between

#include #include #define WIDTH 1000 #define HEIGHT 1000 typedef struct s_pair { int x; int y; } t_pair; char pixels[HEIGHT][WIDTH]; void *add_to_global(void *param) { t_pair *input; …
lkallio
  • 19
  • 2
1
vote
2 answers

pthreads parallelization incorrect result

I'm writing a C-program using pthreads. The goal is to compute the multiples of given numbers by passing them as arguments. The numbers to multiply and the amount of multiples are free to choose. The program is compiled with gcc -lpthread -Wall…
Kitsune
  • 117
  • 5
1
vote
0 answers

pthread_join after pthread_cancel necessary?

I have a multi-threaded program, which each thread runs in a loop if a variable exit_requested = 0. Once SIGINT is received by the main thread, the SIGINT handler makes exit_requested = 1. Each thread then exits the loop, and the main thread then…
doctopus
  • 5,349
  • 8
  • 53
  • 105
1
vote
2 answers

How to Return Values From thread Back to main()

I am using pthread_create to create a thread that examines the amount of lines in a file, then returns the answer to the main thread. I have tried using pthread_join, and malloc() but I am new to both and must have used them improperly. If anyone…
Alt
  • 21
  • 3
1
vote
1 answer

pthread_join with a return value is giving segmentation fault

I am trying to run the code below which creates a thread using pthread_create, and returns the count from inside the thread. The code is giving me a segmentation fault #include #include #include #include…
1
vote
2 answers

Pthread_join returning variable value as 0

I want to insert pthread_join function on the following code to terminate my threads and get the variables value updated. After that my idea was to make a variable to add the new values I got from the threads and print it out. I have the following…
1
vote
1 answer

How do I create different number of threads in c++?

In my program, I want to get number of threads from user. For example, user enters number of threads as 5, i want to create 5 threads. It is only needed in the beginning of the program. I don't need to change number of threads during the program.…
1
vote
1 answer

Is there a way to join for a specific thread, knowing only its ID?

Given a finite number of doctors and an infinite number of patients (which are generated at random moments (in the while(1) loop ), I need to make a program that describes the scheduling. So far, I made a linked list containing the ids of the…
Andrei Manolache
  • 766
  • 1
  • 8
  • 17
1
vote
1 answer

pthread_join hangs indefinitely __lll_lock_wait_private()

I have multithreaded application where I spawn a few threads and do a pthread_join upon completion. The main thread spawns threads and waits on pthread_join() for the worker threads to join. I am facing a issue where the main thread is waiting…
1
vote
0 answers

Safest way to create joinable threads in a python extension

I'm working on a python extension which spawns threads with pthread. In this minimal example the spawned threads don't join back the main thread in python. On the contrary I have no trouble with running the library when linked with a C++ executable.…
newkid
  • 1,368
  • 1
  • 11
  • 27
1
vote
1 answer

Error reading returned value from passing struct pointer to pthread_exit() in C

I'm trying to pass pointers to struct lower_hyper_id from a thread to the main thread, by the means of pthread_exit() function, that would compare and output the value in the struct. However, i receive an error (Segmentation fault) when i am trying…
Diogo Soares
  • 130
  • 2
  • 8
1
vote
1 answer

can we define a variable before calling pthread-create() function

i try to test multithreading in c language and on Manjaro OS. i write a small code but i faced a strange problem i execute below simple code but i didn't get expected result: #include #include #include #include…
milad
  • 1,854
  • 2
  • 11
  • 27
1
vote
1 answer

Has to join std::thread in std::vector twice to avoid termination from thread dtor

I wrote a parallel program to find the Two Sum problem: #include #include #include #include #include #include #include #include using std::vector; class…
JiaHao Xu
  • 2,452
  • 16
  • 31
1
vote
2 answers

pthread_join() causing segmentation fault

I'm working on understanding threads and have run up against this segmentation fault that I can't seem to correct. I have narrowed down the error to the pthread_join() function, but can't seem to go any further. My understanding is that the for…