Assignment 1

Due Date: Tuesday Oct. 14

1. In some programs it may be useful to add the capability of evaluating arithmetic expressions. For example, in a configuration file, it might be convenient to specify parameters as expressions involving variables, so that the value of those parameters may be simultaneously changed simply changing the one variable.

You will demonstrate how you can implement this capability in a program WITHOUT implemented code to parse and evaluate expressions. Write a program that reads lines from standard input, each line containing an expression, and evaluates it.

Expressions may or may not involve an assignment. If an assignment is done, there is no output. If the expression does not involve an assignment, then the value of the expression is output. For example, the expression '2 + 2' would produce the output '4'. The expression 'a = 3 * 3' would produce no output, but a later expression 'a' would produce the output '9'. Expressions may refer to variables defined (by assignment) in earlier lines.

HINT: Use the program 'bc'.

NOTE: Your program should NOT write code that checks the input to see whether a output is expected. Instead, if output is generated for an expression the program should read and echo it, otherwise it should simply prompt for the next line.

2. Implement linked lists in shared memory, the shared memory being obtained by a call to mmap. Use file (record) locks for synchronization of programs manipulating the lists. You may obtain a lock for an entire list, however if there is more than one list in existence, they should have separate locks. Any number of programs should be able to read the list as long as none are attempting to modify it. Only one program at a time may modify the list, and obtaining a lock for modification prevents other programs from reading from the list. Write a test program to verify that list operations and synchronization work as expected. Later in the course we will examine other synchronization primitives that are more appropriate than file locks.

EXTRA CREDIT: Locking the entire list introduces a performance bottleneck. Modify the program so that individual nodes in the list are locked rather than the entire list. Thus two programs can modify the list (i.e, add or delete nodes) as long as the parts of the list being modified are far enough apart.