CS 321 Spring 2013 > Assignment 2 |
Assignment 2 is due at 5 p.m. Thursday, February 14. It is worth 25 points.
E-mail
answers to the exercises below to
ggchappell@alaska.edu
,
using the subject
“SA2
”.
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.h
is available for inclusion
and the compiler is configured for
using the C++11 threads package.sa2a
with the integer
as a parameter,
obtain the return value,
and print a line in the following form.
sa2a(24) = 37
Here, “24
” should be replaced by the
user-specified value,
and “37
” should be replaced by the
actual return value.
See below for a sample run.
sa2a
should 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.sa2s
is 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 delegate.cpp
.
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.
const
-correctness, etc.).
ggchappell@alaska.edu