handle_event()
).
This approach, while simpler than using an event queue, could cause
a serious problem. In particular, consider the Loading state.
Things start fine -- in response to an 'l'
character,
the handle_event()
function calls
the entry_to()
function. However, consider what happens
when the user enters a character that doesn't correspond to an
existing .bookz
file. The system
calls handle_event()
passing it an 'F'
character, which, in turn, results in a recursive call back
to entry_to()
. Further, if the user continues to enter
characters that don't correspond to an existing .bookz
file, the recursion will get deeper and deeper.
While these calls will "unwind" properly, it is possible for the stack to overflow if the recursion gets too deep. Hence, this is a defect that must be corrected.
zplayer
and bookz_player
must remain
unchanged.
Your refactored code must satisfy the following specifications/constraints.
handle_event()
method.
'F'
and 'S'
events that are
generated in the Loading state), write a single character at a
time to the "write end" of the pipe/FIFO.
Of course, for obvious reasons, the bookz_player
must still execute in its own process.
.zip
file you submit must be named pa6.zip
.
In addition to the source code and makefile, the .zip
file must contain four screenshots that capture the state of the OS
at different times.
Each screenshot must capture the following three things.
You must submit four screenshots in total.
before.png
must be taken before you run
zplayer.
ready.png
must be taken when zplayer is in the Ready
state.
playing.png
must be taken when zplayer is in the
Playing state.
after.png
must be taken after zplayer has terminated.
You must not submit any data files.
exec()
after you
call fork()
however it is not required. You should
think carefully about the implications of both.
If you search the WWW you will find many discussions of how to use semaphores to control access to an event queue. However, those event queues are generally far more flexible than is needed here (and they typically don't make use of a pipe/FIFO).
Also, you may be inclined to think that the mutual exclusion property is an essential aspect of the protocol you must develop. This may or may not be the case -- you may need to be more concerned with sequencing than mutual exclusion.
Finally, remember that, unlike the examples from lecture, at least one of the processes in this assignment (i.e., the process that the state model executes in) is complicated and the code spans multiple files. So, make sure you understand what code is executing in what process.
Copyright 2017