
Part (A) The main() function (thread) should create 1 child thread that does the work of generating the fibonacci sequence.

You do not actually need these either.įILES TO BE SUBMITTED 1) fibonacci.cpp 2) vowcon.cpp 3). CAREFULLY read the man pages for these commands and system calls.

Other timing operations such as ctime(), gettimeofdday(), ftime(), and time() are system functions and can only also be used in a your programs. The 'time' system command can also be used as a system call. The name of this program must be vowcon.cpp OTHER USEFUL INFORMATION There are a few systems calls to get and record timing values in user programs available in C/C++. You will have te may also investigate some of the other pthread functions available to you for this project, and use them if you like. You DO NOT NEED to use sched_yield() to relinquish control of the CPU, but you can use it if you like. from pthreads library for thread coordination. The output of your program should look similar to the following In this part you are *not allowed* to use synchronization primitives such as semaphores, mutexes, mutex locks such as pthread_mutex_lock and pthread_mutex_unlock and conditional variables such as pthread_cond_wait and pthread_cond_signal etc. Your program should work for any phrase of any reasonable length, not just the one given in the example. The order of words in the phrase should not be changed in the print. The main() can decide which thread to begin executing first, or it can leave it to the threads to sort this out. Note that the main thread (running main()) should not print anything itself, the output should be printed by the threads that it creates. The threads should print only the words of the phrase as follows: The vow thread function should print all the words that start with a vowel The con thread function should print all the words starting with a consonant. The main()Ĭan also send the phrase or its parts to the threads. The main() has to create two threads running functions (vow and con). This phrase or its parts can be directly accessed from the main() and from the threads. This phrase can be read into a global variable. vowcon Operating Systems Class The main() in this program should read the phrase from the terminal. The name of this program must be fibonacci.cpp PART B: Printing Words Write a C++ program (using the pthread library) that accepts a phrase of unspecified length on the command line. Note that the vector should only have those many terms as the user wanted. 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 to finish, using the techniques described in lectures pertaining to threads.

When the thread finishes execution, the parent thread will output the sequence generated by the child thread.

Note that the thread function should be iterative when calculating fibonacci (can be recursive, but maybe difficult to implement). The program will then create a separate thread that will generate the Fibonacci numbers placing the sequence in a data structure that is shared by the threads (a vector is probably the most convenient data structure). This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program will generate. Formally, it can be expressed as: fib, = 0 fib, = 1 fibn = fibn-1 + fibn-2 Write a multithreaded C++ program that generates the Fibonacci series using the pthread library. Transcribed image text: PART A: Computing Fibonacci Numbers With Threads The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8.
