Question
I need this in C. Collatz using pthread. Please include on how to compile and run. The Collatz conjecture concerns what happens when we take
I need this in C. Collatz using pthread. Please include on how to compile and run.
The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm:
n = n / 2 if n is even
n = 3n + 1 if n is odd
The conjecture states that when this algorithm is continually applied all positive integers will eventually reach 1. Write a C program using POSIX thread that generates this sequence in the child thread. The starting number will be provided from the command line. The parent can then output the sequence when the child thread completes. The parent process will progress through the following steps:
Establish the global variables to store the sequence
Create the child thread and wait for it to terminate.
Output the sequence.
Exit.
One area of concern with cooperating threads involves synchronization issues. In this exercise, the parent and child threads must be coordinated so that the parent does not output the sequence until the child finishes execution. The parent thread will invoke pthread_join(), which will suspend it until the child thread exits.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started