CSS 430: Code Examples
All source files are located in the following directories under a sub-directory of /usr/apps/CSS430/examples/ at the LAB320: uw1-320-lab.bothell.washington.edu.
Program | Sub Directory | Descriptions | Source Files |
Shell Scripts | shellscripts/ |
These two are shell script examples. The sum10.sh simply prints
out integers from 1 to 10. The sleepNhello.sh sleeps 1 minute
and writes "Hello" in the tmp file. In Unix, if you run a
process in background with the "nohup" option, that process can
continue running even after your log out from the system. To see this
behavior,
sum10 nohup sleepNhello & exit |
sleepNhello.sh, sum10.sh |
Program | Sub Directory | Descriptions | Source Files |
Producer and consumer | bundedbuffer/ |
This is an example of a producer and a consumer thread that shares a
bounded buffer. The producer repeats entering an incremented interger
number into the bounded buffer, from which the consumer picks up and
prints out those integers. Without a proposer synchronization, the
consumer may not receive correctly incremented integers. The
count.cpp program will find such a gap among integers printed
out from the consumer. Run by typing:
java ProducerConsumer | count |
ProducerConsumer.java, count.cpp |
Unix semaphores | semaphores/ |
This is a sample program that uses the Unix semop( ) system call. Three processes allocate a Unix shared region, repeatedly go into a critical section enbraced with P and V operations, and properly increment an integer in that region. To see a correct behavior, run by typing:sem or sem | countYou can see the shared integer incremented sequentiall. |
sem.cpp, count.cpp |
Program | Sub Directory | Descriptions | Source Files |
Dynamic link | dynamiclink/ |
The dynamiclink.cpp program uploads executable file into its
memory space at run time and executes functions in this executable
code. There are three dynamic-linking libraries: lib1.c,
lib2.c, and lib3.cpp, each including func1 and
func2. In particular, those two functions in lib3.cpp are
overloaded. To see how dynamiclink.cpp links those three
libraries to itself, run by typing:
dyn_cpp library name = ./lib1 function name = func1 library name = ./lib1 function name = func2 library name = ./lib2 function name = func1 library name = ./lib2 function name = func2 library name = ./lib2 function name = func3 library name = ./lib3 function name = func1 library name = ./lib3 function name = func1__Fv |
dynamiclink.cpp, lib1.c lib2.c lib3.cpp lib1.s |
Program | Sub Directory | Descriptions | Source Files |
Matrix muliplication | cache/ |
This computes the multiplication of two matrices a[400][400] and
b[400][400] twice. The first computation is just ordinary
multiplication, while the second computation flips b[400][400] in
diagonal, so that it utilize the cache and virtual memory more
effectively. To see this difference, run by typing
matrix |
matrix.c |
Program | Sub Directory | Descriptions | Source Files |
File sharing | fileptrs/ |
The parent.cpp program spawns two children The parent and the
first child executes the same program, (i.e., parent.cpp). The
second child executes the child.cpp. Since those two children
inherit the pointers to the same file strcutre table entry, all the
processes share the same file descriptor #3 and increments the same
file pointer in concurrent. The another.cpp program runs
independently of the other processes, and thus reads the same file
from its top.
To see this difference, run by typing
parent |
parent.cpp, child.cpp, another.cpp sample.dat |