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

Most efficient way to spawn n pthreads with the same parameters in C

I have 32 threads that I know the input parameters to ahead of time, nothing changes inside the function (other than the memory buffer that each thread interacts with). In pseudo C code this is my design pattern: // declare 32 pthreads as global…
lee
  • 740
  • 2
  • 11
  • 24
0
votes
1 answer

C Code: Can somebody explain why process ID printed is the same in this example?

I've tried quite some time to analyse this and I can come up with only one answer - that the process ID printed will be different. but gcc is printing the same value. Can anybody explain why its so? Please find below…
Arun
  • 131
  • 1
  • 12
0
votes
0 answers

after pthread_cancel(), pthread_join() function call hangup

I have written an application, which creates a thread and runs into while loop. In the application after spawning a thread, i have overridden the fork() syscall with pthread_atfork(). [when fork is called, a prepare function call is called which…
0
votes
1 answer

How to convert * to double/float with pthread, pthread_exit

I need to create a program which calculates recursion (for certain sequence). When I use int and decleare a recursion, that calculates values without floating numbers (like fibonacci sequence, which returns only neutral numbers) it works. However,…
Michał
  • 43
  • 1
  • 7
0
votes
1 answer

Writing and reading from a buffer with pthread

I am trying to use pthread. In my code below I have defined two global variables (arg1 and arg2) and in the main function I start filling each element of arg2 with 1. I want the pthread to print the 101-th element of arg2 as soon as it is filled by…
zahra
  • 175
  • 1
  • 10
0
votes
0 answers

PThread Segmentation Fault, Incrementor/Decrementor

I keep getting a Seg Fault, im assuming its trying to access past DECREMENTORS 4 that doesn't exit. I added in a couple of print statements to help narrow the problem. What im trying to create is a simple increment, decrement program of a threads…
0
votes
1 answer

gcc segmentation fault if pthread_create is called

This piece of code seems to throw a segmentation fault, but if the pthread_create line is commented out, the segfault disappears. pthread_t thread_id[device_count]; if (params.revision == 3) { startTime = time(NULL); unsigned long number =…
Amit
  • 3,952
  • 7
  • 46
  • 80
0
votes
2 answers

Why printf is not working with multple threads in c?

In the code below I create 8 threads and each of those prints a string and its id. However, I don't see any printf output in stdout from PrintHello function. One strange thing that is happening is that if run the main using debugger (CLion) printf…
Yos
  • 301
  • 4
  • 15
0
votes
1 answer

using a pthread read a file and perform an operation

I am fairly new to C and I am making a C program that should works like this: it has one thread which reads a file with a double on each line of the file, and: it should be able to read files of any size. after reading the double it should perform…
S. N
  • 3,456
  • 12
  • 42
  • 65
0
votes
0 answers

Program compiled by apple clang can't read the latest TLS data in pthread_key_create destructor

Under Macos, program compiled by apple clang can't read the latest TLS data in pthread_key_create destructor, while if it is compiled by gcc at the same environment, it works as expected. Here is a self-contained example: #include #include…
zjs
  • 43
  • 2
0
votes
3 answers

pthread_detach doesn't change anything

I understand pthread_detach(pid) that: "storage for the thread thread can be reclaimed when that thread terminate" (as per http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_detach.html) However, I understand that means that once the pid…
Ziad
  • 63
  • 1
  • 9
0
votes
1 answer

POSIX returning and printing array prthread_join()?

I am trying to find the prime factorization of multiple numbers. If the user types 15 80 77 it will create a thread for each input and have the thread return a array of the factorization which will then be printed. However I am recieving two errors.…
user9443617
0
votes
1 answer

Increasing a global counter variable from within a thread without having to wait for each individual thread

My goal is to create a program that evaluates the performance gains from increasing the number of threads the program can use. I evaluate the performance by using the Monte Carlo method to calculate pi. Each thread should create 1 random coordinate…
Razonixx
  • 15
  • 2
0
votes
1 answer

program intermittently stuck with main reporting a different thread id as opposed to the thread itself

I am trying to figure out how multi-threading works, this is my code : #include #include #include #include #include #include static pthread_cond_t threadDied =…
AshR
  • 32
  • 5
0
votes
1 answer

Pause a thread on a controller method call C#

My Question is about C# Threading. I want to pause a Thread on a controller method call. I have a little idea that it can be done by joining our main thread from my already running thread to whom I want to pause until controller method completes…