answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<time.h>

#include<pthread.h>

#include<stdlib.h>

#include<sys/types.h> /* need to calculate which I will implement later */

void *fibr(void *n);

void *fibr_1(void *k);

signed long long int fibonacci(signed long long int);

int main(){

clock_t begin, end;

double time_spent;

pthread_t tid,tid1;

int result,result1;

signed long long int n=6;

signed long long int m=7;

result=pthread_create(&tid,NULL,fibr,&n);

if(result){

perror("pthread_create");

return 1;

}

result1=pthread_create(&tid1,NULL,fibr,&m);

if(result1){

perror("pthread_create");

return 1;

}

if(pthread_join(tid,NULL)){

perror("pthread_join");

return 1;

}

if(pthread_join(tid1,NULL)){

perror("pthread_join");

return 1;

}

printf("Fib value=%lld\n",n+m);

pthread_exit(NULL);

}

void *fibr(void *n){

signed long long int *y=n;

signed long long int x=*y;

pthread_t tid2,tid3;

signed long long int i,j;

/* How do I assign values to i , j in order to

achieve the level viz fib(n-2)....fib(n-4) */

if(pthread_create(&tid2,NULL,fibr_1,&i))

{

perror("pthread_create");

}

if(pthread_create(&tid3,NULL,fibr_1,&j))

{

perror("pthread_create");

}

if(pthread_join(tid2,NULL))

{

perror("pthread_join");

}

if(pthread_join(tid3,NULL))

{

perror("pthread_join");

}

/* How to return the values of i, j combined with *y . if I do *y+i+j, the result

is not coming correctly */

*y=fibonacci(x);

return NULL;

}

void *fibr_1(void *k){

long long int *a=k;

long long int b=*a;

*a=fibonacci(b);

return NULL;

}

signed long long int fibonacci(signed long long int x){

if((x==0)(x==1))

return x;

return fibonacci(x-1)+fibonacci(x-2);

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

Enerates the Fibonacci series using Pthread thread library?

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A multithreaded program that generates the Fibonacci series using Pthreads?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.


What components of program state are shared across threads in a multithreaded process?

Obviously Heap Memory


Write a program that generates the Fibonacci series up to 200?

class Program { static void Main(string[] args) { int n1, n2, n3,i; n1 = 0; n2 = 1; for (i = 1; i &lt;= 20; i++) { n3 = n1 + n2; if (n3 &lt;= 200) { Console.WriteLine(n3); n1 = n2; n2 = n3; } } Console.ReadKey(); } }


Can you explain the program of Fibonacci series in c?

You mean you have written a program, but you don't understand it? Well, how could I explain it without seeing it?


Write a program to print the Fibonacci series in php upto input value using recursive function?

The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } So your final result would look like. &lt;?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } ?&gt;

Related questions

What mean by multithreaded program?

A multithreaded program is one that has multiple threads in execution. They may execute parallel to one another or totally without relation to one another. In Java you can create multithreaded programs using Java threads.


What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.


What components of program state are shared across threads in a multithreaded process?

Obviously Heap Memory


Program that generates and displays the Fibonacci?

/*WAP to display Fibonacci series*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,a=0,b=1,c; scanf("%d",&amp;n); printf("%d\n%d",a,b); for(i=0;i&lt;n;i++) { c=a+b; a=b; b=c; printf("\n%d",c); } getch(); }


Write a program that generates the Fibonacci series up to 200?

class Program { static void Main(string[] args) { int n1, n2, n3,i; n1 = 0; n2 = 1; for (i = 1; i &lt;= 20; i++) { n3 = n1 + n2; if (n3 &lt;= 200) { Console.WriteLine(n3); n1 = n2; n2 = n3; } } Console.ReadKey(); } }


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


Write a program using while loop that generates Fabonaci series up to 200?

//to generate Fibonacci series upto a range of 200....(in C).... #include&lt;stdio.h&gt; main() { int a,b,c,i; a=0; b=1; printf("\n FIBONACCI SERIES .....\t"); i=1; while(i&lt;=(200-2)) { c=a+b; printf("\t%d",c); a=b; b=c; i++; } }


Can you explain the program of Fibonacci series in c?

You mean you have written a program, but you don't understand it? Well, how could I explain it without seeing it?


What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


Program to generate Fibonacci series using storage class in c plus plus?

i dn't know. haha


Why java called as multithreaded programming?

Java is called multithreaded because it allows the programmer to define multiple threads of execution manually. The main program would continue to execute as one thread and we can speed up the processing by declaring individual threads. Threads in Java can be created in two ways: 1. By extending the Thread class &amp; 2. By implementing the Runnable interface


In a multithreaded environment a is defined as the unit of resource allocation and a unit of protection?

In a multithreaded environment, a mutex (mutual exclusion) is used as the unit of resource allocation and a unit of protection. It ensures that only one thread can access a shared resource at any given time, preventing race conditions and data corruption. This synchronization mechanism helps maintain data integrity and consistency in a concurrent program.