JMU
Programming Assignment 7


1 Summary

The (fictitious) company zmedia has had great success with the most recent zplayer and users are very happy with the functionality of the user interface. However, the marketing department believes they can expand the company's "reach". In particular, several focus groups and surveys have provided evidence that there is a segment of the market that, while not willing to purchase a zplayer, is willing to use a free product even if it displays advertisements.

To that end, zmedia has decided to distribute two different products, the existing zplayer (with the advanced user interface) and a stripped-down product called free_bookz_player that just displays a bookz from start to finish (like the original bookz_player), but with periodic brief advertisements.

2 Specifications and Other Documents

zmedia has provided you with the following documents.

3 A Collection of adz

zmedia has provided you with a collection of adz that corresponds to the collection of "adventure" bookz that you have worked with in the past. (Note that, at this point, the have only sold adz for two of the bookz, but that should be enough for testing purposes.)

You must uncompress it (using gzip) and extract the collection (using tar) before using it, but you must not change any of the individual file names or the contents of the files.

4 Additional Specifications/Constraints

In addition to conforming to the documents provided by zmedia (and all related course policies), your code must satisfy the following additional specifications/constraints.
  1. The main() function of the free_bookz_player must call the display_all() function in the bookz_lib module directly. In other words, the bookz must be displayed in the main thread.
  2. The start_adz() function must be called in a "helper" thread.
  3. There must be no interaction between the two threads and they must not share any variables.
  4. Both the bookz and the adz must be displayed on STDOUT_FILENO.

5 Help

5.1 Existing Code

You will need to use the existing bookz_lib, and you should not need to modify it.

You will not need to use the existing bookz_player module, zplayer module, or the states/statemodel (since the free_bookz_player has a very simple user interface).

5.2 Displaying the Number of Lines and Ads

The last thing the system must display is the number of lines and the number of ads. Given the specifications and constraints, this must happen in the free_bookz_player (i.e., in the main thread). The number of lines can be handled as in PA1. The number of ads is returned by the start_adz() function. However, since start_adz() runs in the helper thread, it must be obtained by the free_bookz_player indirectly.

5.3 Shared or Not?

As we discussed in lecture, a variable is shared if it is used by more than one thread.

The variable lines_read has file scope and external linkage. As a result it can be (and is) used by multiple functions and in multiple translation units. However, since it is only used by the main thread, it is not shared.

You must not use a variable with file scope and/or external linkage to keep track of and display the number of advertisements (since it would be used by both the helper thread and the main thread and, hence, would be shared).

5.4 Sleeping

You might be tempted to use an "interval timer" [like settimer()] for this system, but you shouldn't do so. "Interval timers" use signals and, unless they are absolutely necessary, signals should be avoided in multi-threaded programs (because all threads share the same signal dispositions). You should probably use sleep() instead.

5.5 Testing

You will want to test situations in which the lines of the bookz take longer to display than the advertisments and situations in which the advertisements take longer to display than the lines of the bookz. To that end, you may need to temporarily modify some of the files.

5.6 Converting Strings to Numbers

You may use C library functions (e.g., atoi()) to convert strings to numbers.

Copyright 2017