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

C++ : Passing threadID to function anomaly

I implemented a concurrent queue with two methods: add (enqueue) & remove (dequeue). To test my implementation using 2 threads, I generated 10 (NUMBER_OF_OPERATIONS) random numbers between 0 and 1 in a method called getRandom(). This allows me to…
John
  • 17
  • 3
0
votes
1 answer

fork in multithread process, allocated memory for thread

In the code below, there is no memory leak in parent and child as far as I checked with valgrind. Child total heap usage: 1 allocs, 1 frees, 272 bytes allocated Parent total heap usage: 2 allocs, 2 frees, 1,296 bytes allocated I have two…
user4612022
0
votes
1 answer

Memory leakage in windows pthread. `pthread_join` does not deallocate memory

The simple test: void testMemoryLeak_PthreadCreateJoin(void) { auto taskFunction = [](void*args) -> void* { return nullptr; }; pthread_t pth; int err = pthread_create(&pth, /*attr*/nullptr, taskFunction, /*args*/nullptr); …
kyb
  • 7,233
  • 5
  • 52
  • 105
0
votes
1 answer

pthread_join segmentation fault in C

The purpose of my program is to open a directory, and for every file within it, create a thread for it and put it's formation in a struct array (files). But even if I change those functions to only {return NULL;} I still get a segmentation fault…
asdasda
  • 21
  • 1
  • 9
0
votes
1 answer

Is it mandatory to join a non-detached thread?

I create a non-detached thread which can be stopped through 2 different methods. One of them (stop()) provides a sync interface by joining to the spawned thread while the other one (stopAsync()) just sets the control variable m_continue to false and…
Murat Şeker
  • 1,651
  • 1
  • 16
  • 29
0
votes
1 answer

My loop doesnt run properly in multi-threading

I try to write a multi-thread program, and meet some problems. After I run main.c, and I get i: 0 new thread 0 new thread 1 i: 1 i: 1 //main.c #include #include #include void* routine(void* arg) { int…
Shawn Huang
  • 187
  • 2
  • 14
0
votes
2 answers

Questions on pthread_join() and pthread_create()

This is the declaration of pthread_create: int pthread_create(pthread_t *thread, const pthread_attr_t *attr,void * (*start_routine) (void *), void *arg); it contains a function start_routine. So when we call pthread_create, the function…
BobHU
  • 402
  • 5
  • 18
0
votes
1 answer

What happens if one deletes an object with a running pthread?

I have an object that uses pthreads. Its constructor creates several threads. The class's destructor calls pthread_join on all these threads. What would happen during a delete, if it didn't? I.e., what happens to a non-terminated thread, if the…
0
votes
1 answer

pthread_join() not working

I have got troubles with my code. The following code starts n threads that compete to find the max value of each diagonal of n different matrices. #include #include #include #include #include…
Giulio Paoli
  • 85
  • 11
0
votes
1 answer

Creating and Joining pthreads using vector::iterator

Working on a simple project to tally multiple txt files using threads. The only error I'm getting in compilation involves the vector::iterator being used in the pthread_join loop. The error is: error: invalid conversion from long…
user3776749
  • 667
  • 1
  • 10
  • 20
0
votes
0 answers

How to achieve contention condition in reader writer program? what does it indicate? I have my code but then it indicates something wrong.

I want to add a contention condition in this code in order to understand the nature of threads. But i am not able to get it through this code. #include #include #include
Learner
  • 512
  • 2
  • 7
  • 23
0
votes
1 answer

single thread and multiple thread

Would anyone know a way of explaining or could you direct me to some material regarding single Thread and multiple thread? I don't understand them at all. Every explanation I read is in very complicated English. I want to understand them completely.…
0
votes
2 answers

Simple example for pthread_join deadlock

I am looking for a very simple example to demonstrate a deadlock using pthread_join; however, this is not trivial. I started with this: void* joinit(void* tid) { pthread_t* tid_c = (pthread_t*)tid; int retval = pthread_join(*tid_c, NULL); …
今天春天
  • 941
  • 1
  • 13
  • 27
0
votes
1 answer

Debian pthread_join bus error

I am sitting on a Beaglebone Black and having problem with pthread_join, which gives me Bus error. See the following code below. This is taken directly from a Youtube-tutorial on pthreads. #include #include #include…
Pavoo
  • 75
  • 2
  • 6
0
votes
3 answers

Trouble with signal catching and thread termination - C

I'm writing a program in c, which make use of threads, and i also want to catch Ctrl+C signal from the user. So, before i go multithreading, i make the signal catching. My main thread (i mean besides the actual main thread that the program runs on),…
Adiel
  • 1,203
  • 3
  • 18
  • 31