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

Why is the same argv[] printed twice in the two threads?

I just started programming in multiple threading and tinkering with some templates around, I produced this possibly horrible code: #include #include #include #include #include typedef…
mayank
  • 176
  • 1
  • 12
0
votes
0 answers

How can I change the string to the Thread class in ruby on rails

Let's understand the scenario, I have to call a third party API in one of the API calls to my server (let say A) from the mobile app. That third party API takes almost 12-15 seconds to execute. However, in the next consecutive API call to my server…
0
votes
2 answers

Returning void pointer in pthread

I just started learning multi-threading in C++ with pthreads. I am working with the following code: struct ArgT{ int a; int b; ArgT(int a, int b) : a(a), b(b) {} ArgT() :a(0), b(0) {} }; void* worker(void*…
HariP19
  • 29
  • 1
  • 6
0
votes
1 answer

Why does thread just die if i dont set 'pthread_join'

#include #include #include int count = 0; pthread_mutex_t MUTEX = PTHREAD_MUTEX_INITIALIZER; void* func1(void* a){ pthread_mutex_lock(&MUTEX); for(;count < 4;count++){ printf("LOOP 1:…
co_lin
  • 125
  • 7
0
votes
2 answers

C: Printing out multiple threads' ID's before they execute anything?

I am wanting to generate a number of threads based off of how many a user wishes to create, and each of these threads is to carry out one function "readFiles". However, before the threads can each execute any of the meaningful code from readFiles,…
PluffTed
  • 53
  • 5
0
votes
3 answers

pthread_join and void** - error understanding

I wrote a simple task like the following. It prints a string, increments the global variable glob, and returns its value, through the pthread_exit, to the pthread_join. #include #include #include int glob =…
Gennaro Arguzzi
  • 769
  • 1
  • 14
  • 27
0
votes
0 answers

pthread_join hangs forever C++

I am running this g_test where I simply initialize and close a client. TEST(safIpc, createAndCloseClient) { std::shared_ptr safIpc = std::make_shared(); const std::string& app1 {"/testApp1"}; …
0
votes
1 answer

How to initialized pthread_t variable in class constructor

How to initialized pthread_t variable in class constructor. C++ Static Analysis(coverity) Error: Non-static class member threadId is not initialized in this constructor nor in any functions that it calls. #include #include…
0
votes
1 answer

pthread_join hangs accordingly to random global variable value

I have built this code utilizing pthreads. The goal is to build an array X[N][D] and assign random values to it. You could read the elements of this array as the coefficients of some points. On the next step I am trying to calculate an array…
Giannis
  • 75
  • 9
0
votes
1 answer

pthread_join wrong type of argument

I've been trying to create a simple thread that reads from stdin and stores input to a linked list. When creating and joining the thread I get the following error: warning: passing argument 1 of ‘pthread_join’ makes integer from pointer without a…
0
votes
2 answers

Why does pthread_join fail on the last iteration (giving segmentation fault)?

Multi-threading beginner here. On exactly the 5th iteration (i.e. when executing pthread_join(threadID[4], NULL), my program fails with a segmentation fault. I am creating multiple threads to add/subtract 1 from a counter variable to study race…
bantz
  • 36
  • 1
  • 4
0
votes
0 answers

my C program using pthreads gets stuck and i cant figure it out why

I cant seem to see whre is the problem of my program it do all my computations but at some point get stuck. and i cant figure it out, any recomendations? first i define the structure #include #include #include…
BloodGreen
  • 45
  • 6
0
votes
1 answer

Reader threads not exiting - Posix Pthreads

I have to create a solution to the readers writers problem using posix pthreads, I have condensed my code down to pseudocode mixed with C to reduce the size of the code. The writer thread finishes fine but the reader threads never terminate/exit so…
Kevin
  • 43
  • 1
  • 7
0
votes
0 answers

Program terminates on pthread_join

My program creates some pthreads in a for loop that do some work, then waits for them to finish in another for loop using pthread_join and then it is supposed to show some output. The problem is that the program doesn't get passed the pthread_join…
Petros21
  • 45
  • 7
0
votes
1 answer

How to use a struct pointer returned to the in the main from a thread function?

I am writing a program that takes integers as command line arguments. For each of these numbers I have to create a thread which calculates Fibonacci series up to that number. That function returns a struct pointer to the main where the data is…