In language C linux system Threads Write a multithreaded Li

In language C, linux system

Threads • Write a multi-threaded Linux program named fibonacci.c which accepts a single integer parameter from the command line (N), and then prints out the first N

Fibonacci numbers to the screen . You must launch one thread which computes all N Fibonacci numbers, storing them into a data structure accessible by the main thread Hint: a dynamically allocated array is simple! Declare a global variable that is a pointer to ints. In main), dynamically allocate enough space to hold the N values. Have your thread function then use the global variable (pointer to the ints) to store the values You could also have the thread function d space and then return the pointer via pthread_exit). See tutorial video posted to YouTube on dynamic memory allocation and threads for more ynamically allocate the After launching the calculating thread, the main thread must wait until the calculating thread completes Once the calculating thread completes, the main thread writes the results to the screen The calculating thread must not write any text to the screen. Measuring System Call Overhead In this question, you will run a little experiment to measure the overhead of system calls. We will focus on two particular calls: fork). which is supposed to be expensive, and getpid, which is one of the simplest systems call available Use the following source code and create a file named measureSystemCall.c: #include #include #include #include .Your Answers Here .double timespec_ to_ms(struct timespec ts) return ts-tv_sec*1000.0 ts-tv nsec 1000000.0; int main struct timespec starttime, end time clock gettime CLOCK_PROCESS CPUTIME ID, &start; time) *begin timing end timing clock_gettime CLOCK_PROCESS_CPUTIME_ID, kend_time) printf(\"%f msn.. timespec-to-ms(&end-time;) timespec_to ms(&start;_time));

Solution

we can add the logic of series in between start and end time the code is as follows

#include <stdio.h>
int main()
{
   //variables to be used
int i, n, zeroth = 0, first = 1, nextNumber = 0;
   //input the value of n
printf(\"Enter the number of terms: \");
scanf(\"%d\", &n);
   //for loop for series
for (i = 1; i <= n; ++i)
{
// Prints the first terms.
if(i == 1)
{
printf(\"%d, \", zeroth);
continue;
}
       //print second term
if(i == 2)
{
printf(\"%d, \", first);
continue;
}
       //add as per fibbo series and print
nextNumber = zeroth + first;
zeroth = first;
first = nextNumber;
printf(\"%d, \", nextNumber);
}
return 0;
}

please add the follwoing and run as per your question

In language C, linux system Threads • Write a multi-threaded Linux program named fibonacci.c which accepts a single integer parameter from the command line (N),

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site