CS 3733 Operating Systems, Fall 2007 Assignment 4 Comments
You should not modify the item.h or solution_buffer.c files.
Do not return negative values from main.
Do not put the producer or consumer in solution_buffer.c.
You do not need to allocate space for the solution each time the producer
produces something.
This is very wasteful.
Error handling is difficult.
Easy to produce memory leaks.
I found memory leaks in half of the programs I graded.
Dynamic memory allocation should be avoided unless necessary.
What is wrong with the following code:
int *i;
i = (int *)malloc(sizeof(int));
for (*i=0;*i<10;(*i)++)
printf("*");
If you use malloc, you need to test for an error and handle the error
correctly.
rand()%N does not produce random values. It may be biased
towards smaller numbers for most values of N.
Do not call exit when a method detects an error.
Make sure each source file you turn in is labeled.
There are 2 (or more) ways for the producer to produce an array of unique
integers between 0 and N-1:
For each position in the array, generate a random integer in the
right range. Compare to all previously generated values.
If not unique, try again.
For each number between 0 and N-1, create a random number giving
its position in the array. If the array is initially filled with
-1's only one test is needed to see if you need to try again.