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

use of pointer to pointer in pthread_join function

int pthread_join(pthread_t thread, void **retval); According to the man page pthread_join should use a pointer to a pointer as argument to store the return value.I cant understand why its designed that way.Is it sufficient to use a pointer variable…
Fazil Uruniyengal
  • 286
  • 1
  • 3
  • 15
1
vote
1 answer

pthread_join and pthread_exit

int pthread_join(pthread_t thread, void **retval); void pthread_exit(void *retval); in the pthread_exit call we are passing a pointer to the value we have to pass.And in pthread_join it should be a pointer to pointer according to the man page.I am…
Fazil Uruniyengal
  • 286
  • 1
  • 3
  • 15
1
vote
1 answer

Peterson's Algorithm to avoid race condition between threads

Details: I am implementing Peterson's Algorithm(below) to avoid race condition. The way I want to do it, is to declare a global integer variable, and create threads one and two. Whenever the thread one had access to the global variable it should…
Neo
  • 349
  • 5
  • 18
1
vote
1 answer

pthread_join() unexpected results

I'm having trouble understanding the pthread_join() function because of the results I am getting. If pthread_join() is supposed to pause the calling thread until the thread of the given thread id finishes it's job then why does the following code…
Kyle Bridenstine
  • 6,055
  • 11
  • 62
  • 100
1
vote
1 answer

pthread_exit return value

This is surprising for me. static int ret = 50; void * thread_func(void *arg) { pthread_exit(&ret); } int main(void) { pthread_t thr; int *exit_status; pthread_create(&thr, NULL, thread_func, NULL); sleep(2); …
Sandeep
  • 18,356
  • 16
  • 68
  • 108
1
vote
1 answer

How to avoid a memory leak by using pthread_cancel?

I have a program which should start a thread. To avoid to exit the software the thread runs in an endless loop and I join the thread. This thread is never supposed to return a value. So now I have the problem that after I call pthread_cancel…
Irgendw Pointer
  • 1,770
  • 3
  • 30
  • 67
1
vote
1 answer

C threading (pthread_create) not working as expected

I want to create multiple threads (10 in the example below) and have each of them run a function. Here is my code: #include #include typedef struct arg_struct { int id; int val; } arg_struct; void *printarg(void…
Joohwan
  • 2,374
  • 1
  • 19
  • 30
1
vote
3 answers

pthread_join:warning: cast from pointer to integer of different size?

My code #include #include #include void * thread_func1(void *args) { printf("thread 1 returning\n"); return ((void *)1); } void * thread_func2(void *args) { printf("thread 2 exiting\n"); …
Charles0429
  • 1,406
  • 5
  • 15
  • 31
1
vote
1 answer

How long after pthread_exit() can pthread_join() be expected to succeed?

I've been tasked with creating a user-level thread library that replicates the functionality of pthread (full disclosure: this is for an OS course). However, I'm unclear as to how pthread_join() and pthread_exit() interact when a thread has already…
piebie
  • 2,652
  • 21
  • 30
1
vote
2 answers

segmentation fault after pthread_join

I'm trying to calculate the value of pi using multiple threads in ubuntu using c. I'm not perfectly familiar with the variables that the pthread_create and pthread_join should get as input, as well as how to deal with type 'void'. I planted some…
Amnon
  • 195
  • 3
  • 12
1
vote
3 answers

how to know which thread was released by pthread_cond_signal

Cheers, I have 2 threads causing logical deadlock => d_santa and d_patuljak (sorry some pieces are written in Croatian and I didn't have the time to translate) d_santa does this void d_santa(){ //dodati join!!! int j; …
Spidey
  • 894
  • 1
  • 13
  • 29
1
vote
0 answers

pthread_join segment fault

I'm doing parallel sorting using pthreads. Currently, I'm working with 4 threads and I have just started out , so right now no threads access same global locations. ( I have declared two variables globally, variables are arrays of large size and I'm…
Roopa
  • 11
  • 1
1
vote
2 answers

Seg fault (core dumped) after pthread_join in C

I keep getting a seg fault (core dump) after pthread_join in my program. It prints out the expected result just fine, but seg faults when joining the thread. I have looked at several other discussions on this topic, but none of the suggested…
Acroyear
  • 1,354
  • 3
  • 22
  • 37
1
vote
1 answer

Stat errors in pthread (S_ISDIR not working)

I am currently attempting to write a program that finds the size of a directory tree as well as the size of all subdirectories within it by creating a thread for each new subdirectory and using that thread to find the size of the subdirectory. It's…
arc
  • 477
  • 2
  • 8
  • 14
1
vote
2 answers

pthread_join causes segmentation error (simple program)

I am just trying to work with multi-threaded programs, but I am having problems with the pthread_join function. The code below is just a simple program I am using to show pthread_join crashing. The output from this code will be: before create child…
keithbhunter
  • 12,258
  • 4
  • 33
  • 58