n CSCI 3250: Lab 3

Lab 3: Multithreaded Fibonacci


Due: Wednesday, February 8, 2012 by 10:00 PM
Assignment ID: lab3

Lab description

Write a multithreaded program that generates the Fibonacci sequence using Pthreads. This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program is to generate. The program will then create a separate thread that will generate the Fibonacci numbers, placing the sequence in a data structure that can be shared by the threads (an array or sharedData). When the child thread finishes execution, the parent thread should output the sequence generated by the child thread.
Name the source code file lab3.cpp.

Example Execution

$ ./lab3 25
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368

Submission

Submit the source code files using the handin program. For example, for this lab, type the following in a terminal exactly as it appears:
  handin  lab3  lab3.cpp

Alternatively, you can submit the assignment from any computer via PeerSpace. After successfully logging into PeerSpace, go to Tools, then Assignments. Click on the Submit link.

Rubric:

Points          Item
----------      --------------------------------------------------------------
_____ / 50  	Program compiled properly (on ranger2)
_____ / 10 	Properly created child thread
_____ / 10	Child thread populated Fibonacci sequence
_____ / 10	Parent thread read Fibonacci sequence
_____ / 20	Executed properly


_____ / 100


Hints

  1. If you get an error like:
    error: 'shmget' was not declared in this scope
    or
    error: 'S_IRUSR' was not declared in this scope
    use man (e.g., man shmget) or a search engine to determine the appropriate header file to include.
  2. Don't forget to use -lpthread when compiling the program. If you don't, you'll get errors like:
    undefined reference to `pthread_create'
    or
    undefined reference to `pthread_join'
  3. If you get an error like:
    lab3.cpp:In function 'void* runner(void*)':
    lab3.cpp:XX: error: invalid conversion from 'void*' to 'const char*'
    lab3.cpp:XX: error:   initializing argument 1 of 'int atoi(const char*)'
    it probably means you need to cast param, which is of type void*, to at least a char*. For example:
    ... = atoi((char*)param);