|CS 321 Spring 2013 > Assignment 2|
Assignment 2 is due at 5 p.m. Thursday, February 14. It is worth 25 points.
using the subject
delegate.cpp, from Exercise A. and
pipeline.cpp, from Exercise B. This file (or a single archive file containing it) should be attached to your e-mail message.
In this exercise, you will write a C++ program that performs a number of computations, spawning a separate thread for each.
Write a complete C++ program as follows.
delegate.cpp, which should include (“
#include”) the header
sa2a.h(on the course web page).
sa2a.his available for inclusion and the compiler is configured for using the C++11 threads package.
sa2awith the integer as a parameter, obtain the return value, and print a line in the following form.
sa2a(24) = 37
24” should be replaced by the
37” should be replaced by the
actual return value.
See below for a sample run.
sa2ashould be done by a separate slave thread spawned for this purpose. Each slave thread should make exactly one call to
sa2a. The master thread should never call this function.
sa2sis prototyped as “
int sa2a(int);”, and that it is thread-safe (able to be called simultaneously by multiple threads). But you should make no other assumptions about
sa2a. So if I rewrite the header to use a different function, then your program should still work.
Here is a sample run of
Actual return values may be different.
Delegated Computation Enter a positive integer (or 0 to end input): 1 Enter a positive integer (or 0 to end input): 2 Enter a positive integer (or 0 to end input): 24 Enter a positive integer (or 0 to end input): 3 Enter a positive integer (or 0 to end input): 4 Enter a positive integer (or 0 to end input): 0 sa2a(3) = 1002 sa2a(4) = 6 sa2a(1) = -5 sa2a(24) = 37 sa2a(2) = 6
The following are standards for all programming assignments in this class.
The above requirement is absolute; if your code does not compile, then there is no point in turning it in.
In addition, to receive full credit, submitted code should satisfy the following conditions.