Question: WRITE PROGRAM IN C THAT MEETS THE FOLLOWING REQUIREMENTS: Declare a number ( n ) as a global variable in main function. Create 2 threads
WRITE PROGRAM IN C THAT MEETS THE FOLLOWING REQUIREMENTS:
- Declare a number (n) as a global variable in main function.
- Create 2 threads in the program.
- Create the first thread to generate and print the Collatz-sequence from n.
- Another thread to find the factorial of the number n.
HERE IS A BASE EXAMPLE OF THE PROGRAM. SOME THINGS NEED TO BE CHANGED:
#include
static int counter=1;
void *mythread(int n){ printf("%d ",n); int i; for(i=1;i int main(int argc,char *argv[]){ pthread_t t1,t2; printf("Main starts here "); pthread_create(&t1,NULL,mythread,3); //sleep(2); pthread_create(&t2,NULL,mythread,4); pthread_join(t1,NULL); pthread_join(t2,NULL); printf("End of Main %d ",counter); return(0); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
