logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

This file discusses Project 3 which involves pthread multithread programming with a stack (array implementation), mutex, and two pthreads.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

 

 

This file discusses Project 3 which involves pthread multithread programming with a stack (array implementation), mutex, and two pthreads.  

 

Please read all of these instructions as failure to comply may result in a loss of points in your grade.

 

Your project deliverables are to be posted to CUNY Blackboard using the Project 3 link.

 

1) Only one source code file as follows with filename as in the example where you will put your own first initial and lastname and your

   own section number. I show the example for my own name with an example section 23 (you use your course section number): JSvadlenka_prj3_sect23_src.c   (or .cpp)

 

 a) At top of the file: your name in comments, for example:  // First_Name Last_Name 

 

 

 b) Next, the gcc or g++ code compilation and linkage command, for example in my case (not yours) it would be:

 // gcc -o JSvadlenka_prj3_sect23_src.c  -o JSvadlenka_prj3_sect23_src.exe 

 

   Note that you will additionally need the -pthread option for compiling and linking.

 

   If your gcc (or g++) command does not appear at the top of your source code file, or if it does not provide both the source and output executable filenames

   in the format as above, or if the source code filename that you upload to Blackboard does not match the source code filename in your gcc (or g++) command, 

   I will subtract points. 

 

    

 c) In-line code comments no fewer than every 5 lines of code which describe your algorithmic steps. Syntax transcriptions of the code are   

    not considered in-line code comments! (For example, I do not want to see the comment for i++ which says "Increment i.")

 

2) An MS Word or PDF document with a write-up of your software design and an explanation of the issues encountered and resolved. (1 page)

   Filename should be according to this example of my own name: JSvadlenka_prj3_sect23_wrt.doc (or pdf)

 

   No ZIP file submissions.

 

 

3) The source code accepts one command line argument which is an output file name.

 

Project 2 Detailed Instructions  (Please read carefully and comply with these instructions in your project) 

-------------------------------

1) The purpose of this project is to put into practice the thread synchronization concepts discussed in Chapter 6. You will apply it to a shared data structure between 

the two pthreads of this project.  The shared data structure will be a stack that is implemented with an array as shown in Chapter 6 Homework problem 7. The array will

consist of integers. Pthread 1 will push all integers from 1 to 120 on to the stack while pthread 2 pops the integers from the stack in a prescribed order discussed further below.  

 

2) You will implement the push(), pop(), and is_empty() functions for the stack from Chapter 6 Homework problem 7 with the ERROR statements replaced by sched_yield(). 

The stack array size is 20. As the stack is a shared data structure between the two pthreads, you have to ensure mutual exclusion access to the stack with entry and exit sections. The entry section to acquire a (mutex) lock will be implemented with the pthread_mutex_lock() function. The exit section (to release the lock) will be implemented with the pthread_mutex_unlock() function.

 

As an example of mutex usage, you define and initialize a pthread mutex as follows (error checking not shown):

 

  pthread_mutex_t myLock;  // define a mutex variable

 

  pthread_mutex_init (&myLock, NULL);  // initialize a mutex variable

 

 

You can acquire and release the locks as follows (error checking not shown):

  pthread_mutex_lock (&myLock);

 

  pthread_mutex_unlock (&mylock);

 

 

3) The Pthread 1 algorithm pushes the integer numbers from 1 to 120 in increasing order on to the stack. It will call sched_yield() after every 10 consecutive

   invocations of push(). It will also call sched_yield if the stack is full. Pthread 1 will also have its own integer variable (pushSum) to hold a running sum of the   

   integers pushed on to the stack. No output to screen or to a file will occur in Pthread 1.

 

4) The Pthread 2 algorithm pops the integers from the stack. If the stack is full, it will pop all integers from the stack and then call sched_yield(). If the stack

   is not full, it will pop just five integers and call sched_yield(). If there are less than five integers on the stack, it will pop all of them and then call

   sched_yield().  Pthread 2 will also have its own integer variable (popSum) to compute a running sum of integers popped from the stack. Pthread 2 will also have

   its own 120-element array (popOrder) to record the order in which integers were popped from the stack. No output to screen or to a file will occur in Pthread 2.

 

5) Your program will make use of the pthreads library functions discussed in lectures. You ARE permitted to use any C++ 

   or C standard I/O library functions or cin or cout for the file output from the main-line thread in item (6) below.

 

6) OUTPUT: After pthreads 1 and 2 terminate, the main-line thread will write the following output to the filename given in the command line argument.

 

   All 120 elements of Pthread 2 popOrder array

   Value of Pthread 1 pushSum 

   Value of Pthread 2 popSum

(5/5)
Attachments:

Expert's Answer

253 Times Downloaded

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

253 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

905 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

795 Answers

Hire Me
expert
AyooluwaEducation

762 Answers

Hire Me
expert
RIZWANAMathematics

879 Answers

Hire Me

Get Free Quote!

412 Experts Online