answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Bezzdna [24]
2 years ago
10

Write a multithreaded program that generates the Fibonacci series using Pthreads thread library. This program should work as fol

lows: The user will enter on the command line the number of Fibonacci numbers that the program is to generate (* in this case 7 *). The program will then create a separate thread that will generate the Fibonacci sequence, placing the sequence in data-code (section) that is shared by the threads (an array isprobably the most convenient data structure). When the thread finishes execution, the parent thread will output the sequence generated by the child thread. Because the parent thread cannot begin outputting the Fibonacci sequence until the child thread finishes, this will require having the parent thread wait for the child thread.
Computers and Technology
1 answer:
Mamont248 [21]2 years ago
4 0

Answer:

#include <pthread.h>

#include <stdio.h>

#include <stdlib.h>

pthread_mutex_t mutex;

int fib[10]; /* this data is shared by the thread(s) */

int in = 0;

void *genFibo(void *param); /* the thread */

int main(int argc, char *argv[])

{

   pthread_attr_t attr;  

   if (argc != 2) {

   fprintf(stderr,"usage: fibthread <integer value>\n");

   return -1;

   }

   int count = atoi(argv[1]);

   if (count < 1) {

   fprintf(stderr,"%d must be>= 1\n", count);

   return -1;

   }

   pthread_attr_init(&attr);

   // Mutex Lock

   pthread_mutex_init(&mutex, NULL);

   // each thread computes fibonacci

   for(int i = 1;i <= count;i++) {

   pthread_t thread;

   pthread_create(&thread, &attr, genFibo, (void*)i);

   pthread_join(thread, NULL);    

   }    

   // print resulting array

   for (int i = 0; i < in;i++) {

   printf("%d ", fib[i]);

   }

   printf("\n");

   pthread_mutex_destroy(&mutex);

}

void *genFibo(void *param)

{

   pthread_mutex_lock(&mutex);

   fib[in++] = fibonacci((int)param);

   pthread_mutex_unlock(&mutex);

   pthread_exit(0);

}

int fibonacci (int x)

{

   if (x <= 1) {

   return 1;

   }

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

}

You might be interested in
Consider the eight bit signed binary number 1110 0101. Convert it to signed decimal from assuming the signed binary number is re
lapo4ka [179]

Answer:

-26

Explanation:

The given binary number is 1110 0101. Also given that the signed binary number is represented using one's compliment.

We begin by computing the 1s complement representation of 1110 0101 by inverting the bits: 00011010

Converting 00011010 to decimal, it corresponds to 26.

So the 1s complement of the original number is 26. This means that the original number was -26.

7 0
2 years ago
A developer needs to create a visualforce page that displays case data. The page will be used by both support reps and support m
shutvik [7]

Answer:

B. Use a new support manager permission sets

Explanation:

According to the requirements, field level security is required so, 1st options is not suitable because it may reduce the maintenance cost but increase the risk of security.

By creating a separate page for each of the two, it will leads to increase in the maintenance cost of the system. So <u>Option C</u> is also not suitable.

Option B is more Suitable as compared to others, that <em>Create a new support manager permission set</em>, with the help of this, both of Support rep and Support manager can visualize their required information with the help of support manager permission. This solution will not compromise the security and not increase the maintenance cost.

7 0
2 years ago
Write a program whose input is a string which contains a character and a phrase, and whose output indicates the number of times
otez555 [7]

Answer:

The program written in python is as follows

def countchr(phrase, char):

     count = 0

     for i in range(len(phrase)):

           if phrase[i] == char:

                 count = count + 1

     return count

phrase = input("Enter a Phrase: ")

char = input("Enter a character: ")

print("Occurence: ",countchr(phrase,char))

Explanation:

To answer this question, I made use of function

This line defines function countchr

def countchr(phrase, char):

This line initializes count to 0

     count = 0

This line iterates through each character of input phrase

     for i in range(len(phrase)):

This line checks if current character equals input character

           if phrase[i] == char:

The count variable is incremented, if the above condition is true

                 count = count + 1

The total number of occurrence is returned using this line

     return count

The main method starts here; This line prompts user for phrase

phrase = input("Enter a Phrase: ")

This line prompts user for a character

char = input("Enter a character: ")

This line prints the number of occurrence of the input charcater in the input phrase

print("Occurence: ",countchr(phrase,char))

4 0
2 years ago
IDaaS is a ________-based identity and access management offering.
Andre45 [30]

Answer:

c) SaaS

Explanation:

Identity as a Service is a company that provides authentication to access the data or resources to the ensured user. They provide access to the ensured users and helps in securing the data from any unauthorized involvement. The process of authentication is cloud-based and is available only for the subscribed users.

8 0
2 years ago
Which command backs up the single database called 'websites' to the file 'websites_backup.sql'?
kaheart [24]

Answer:

(d) mysqldump websites -u root -p > websites_backup.sql

Explanation:

To create a backup mysqldump is used.It is a data backup program.This program was originally written by Igor Romanenko. It creates a backup of file name websites_backup.sql.

So among the given options in the question option d is the correct option which backs up the single database websites in the file website_backup.sql.

8 0
2 years ago
Other questions:
  • Computer hardware had been designed to run a single operating system and a single app, leaving computers vastly underutilized. o
    15·1 answer
  • Which technology had the same effect in the 1920s as the internet did in the 2000s? the widespread effect of technology 1920s 20
    8·1 answer
  • Write c++ program bmi.cpp that asks the user bmi.cpp the weight (in kilograms) and height (in meters).
    12·1 answer
  • Which use case can be accomplished using a custom link? Choose 3 ans A. Navigate to a process to update the current record. B. N
    10·1 answer
  • Write an application that throws and catches an ArithmeticException when you attempt to take the square root of a negative value
    15·1 answer
  • Thelma is a web developer for a bowling league. She wants visitors to the website to be able to print web pages, such as league
    14·1 answer
  • Enter a nested function in cell G8 that displays the word Flag if the Payment Type is Credit and the Amount is greater than or e
    9·1 answer
  • Which of these are characteristics of a Python data type? Check all that apply.
    11·1 answer
  • PLEASE HELP!!~~
    7·1 answer
  • You are an IT manager at Gigantic Life Insurance. You have a new desktop support person starting today whose experience is limit
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!