Discussion Section: Monday, March 29, 1999
More Help with Lab 3


Global File List Variable
 

We need to keep track of the number of open files because we are only allowed to have 16 open at a time.

One way to implement this is by keeping an open file number as a global variable and then incrementing and decrementing as needed (when you open and close files).

If you do this you may need to add some helper functions to do things such as return the number of open files.

If you want you can simply add functionality to the List class which allows it to keep track of how many items it has.

You can implement this in any other way that you wish.


If you choose to add functionality to the List class...   you will need to do things such as the following.

in list.h

in list.cc

List::List()  // the constructor
add code to set the numlistitems to 0

At the appropriate place in the function increment the numlistitems

the updates should occur in places like this...


These may not be the only places in your program where you have to update, but are some suggestions about the kind of places that you may need to think about it.

You will probably need to add some helper functions to the list class as well.  It will make your life easier when adding and removing files from the openfilelist.  I will leave it to you to figure out what features you need and to add the functionality as is appropriate.
 

Don't Forget...

Don't forget that you may have to add functionality in other places.  For example, in system.cc.

Cleanup() is a function which deallocates all global data structures before halting the program.

Cleanup()


The Synchronized Console (see progtest.cc)

In SynchConsole.h

SynchConsole

In SynchConsole.cc

you may need...

// Data structures needed for the console test.
// Threads making I/O requests wait on a Semaphore to // delay until the I/O completes.

static Console *console;
static Semaphore *readAvail;
static Semaphore *writeDone;

SynchConsole Constructor     console = new Console(in, out, ReadAvail, WriteDone, 0);
    readAvail = new Semaphore("read avail", 0);
    writeDone = new Semaphore("write done", 0);

SynchConsole destructor

getChar function         readAvail->P();    // wait for character to arrive
        ch = console->GetChar();

putChar function

        console->PutChar(ch);   // echo it!
        writeDone->P() ;        // wait for write to finish
 

Test Files...