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

Joining threads in a loop - Conversion error

So I'm trying to join threads in a for loop but it's giving me the error: invalid conversion from 'pthread_t* {aka long unsigned int*}' to 'pthread_t {aka long unsigned int}'. The codes are as below and any help would be greatly appreciated!…
6TTW014
  • 627
  • 2
  • 11
  • 24
0
votes
1 answer

Thread join waits forever: join hangs or waits forever

I have a code like below void CLogThread::run() { m_alive = True; //only place where m_alive (declared volatile) set to true while (m_alive) { //logic here } } void CLogThread::stop() { m_alive = False; } void…
Nasir
  • 708
  • 2
  • 11
  • 28
0
votes
2 answers

segmentation fault joining thread number 5 (pthread_join)

I'm trying to solve a small problem of synchronization. but when I join the threads i get segment fault of the fifth iteration! If i only create 4 threads works perfect. Here I leave the code with some basics of what to do the thread. #include…
0
votes
1 answer

Can pthread_join() cause sequential execution?

When I use the pthread_join(), I am not sure if it is in the right spot. As it is now, would it wait for the thread to exit before iterating through the loop again? I guess what I am asking is should I take it out of the double for loop and create…
willko747
  • 517
  • 1
  • 6
  • 13
0
votes
1 answer

Multithreading a password checker in C

Currently attempting to get this program to use multithreading using pthread_create, pthread_join, pthread_exit, and pthread_self. I then intend to use crypt_r in place of crypt in my code. It will only be able to go up to 8 threads, but I don't…
m96
  • 199
  • 1
  • 3
  • 10
0
votes
2 answers

Pthreads update on global 2D array segfaults on execution

Hi all and thanks for your time. I am trying to parallelise a program which executes some commands and I thought pthreads would be a good option. But I am running into some issues. This is where I start the threads: void timetravel(command_stream_t…
Avi C
  • 176
  • 1
  • 15
0
votes
1 answer

Pthread_join & Pthread_exit in c

#include #include #include void * function(void *); main() { pthread_t p[5]; int j; int *arg1[4]; int arr[5]={1,2,3,4,5}; for(j=0;j<=4;j++) pthread_create(&p[j],NULL,function,&arr[j]); …
user1762571
  • 1,888
  • 7
  • 28
  • 47
0
votes
4 answers

Order of running threads in pthreads

In the following program, what are the possibilities for the ordering of threads? Assuming "function" will print thread id which is unique (since here we have only one process). I always get the order th1,th2! #include #include…
Sara
  • 2,308
  • 11
  • 50
  • 76
0
votes
1 answer

Thread doesn't wake up after join

I've got a GUI interface which has a start and a cancel button. After starting, the main thread which is the GUI thread, is creating a second thread which will do the actual work. When pressing the cancel button, all it does is set a boolean value…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
0
votes
3 answers

Returning single integer value from thread

I need help returning integer value from thread. I have tried several things and can't get it to work. I am new to C and yes this is homework, but I am stuck and need some help on this. I have created the pointer in the thread but when I pass it…
0
votes
2 answers

reading file line by line using pthreads ... exits unexpectedly

I have the following code: /*//not important FILE * INFILE; list_file = optarg; if( ( INFILE = fopen( list_file, "a+" ) ) == NULL ) { fprintf( stderr, "Can't open input file\n"); exit(0); } */ …
ShaMora
  • 67
  • 2
  • 10
0
votes
1 answer

pthread_join receiving results from function in a array

I'm working with pthreads in C and have run into problems(again). I am trying to send results as an array of a function to my main thread. This code finds the largest value for each worker(1worker/row) and saves the indexes for that value. So far so…
0
votes
1 answer

pthread_join crashes with core dumped segfault

I have the following code that causes segfault at pthread_join calls. I'm sorry for many lines, but every char can be important. If it's important, the same code works under WinAPI good and without any errors. void solution_of_matrix(int…
zerospiel
  • 632
  • 8
  • 20
0
votes
2 answers

Problems with joining threads

I've got some issue with a part of my perl script, bothering me for days now. To summarize the purpose is to read in a large file in chunks and do some operation on the input stream (not relevant for my question). When I first implemented it, I just…
achschneid
  • 67
  • 7
0
votes
2 answers

How to control number of threads by using pthread_join in C?

I have created a C program which will read 20000 strings from a text file, and send it to other program. I have used a while to loop through this text file and create threads which will send that text to the other program. But I want only 4 threads…
CodeCodeCode
  • 459
  • 1
  • 12
  • 21