NAME message_reader, message_writer, message_reader_mm, message_writer_mm SYNOPSIS #include "mymessage.h" int message_reader(void) ; int message_writer(int m) ; int message_reader_mm(char * msg, int len) ; int message_writer_mm(char * msg) ; DESCRIPTION message_reader performs a dequeue of the ring buffer, using the mymonitor kernel monitor for thread safety. Will wait if the ring buffer is empty. Returns the dequeued character or -1 on error. message_writer performs an enqueue on the ring buffer of the of the argument, using the mymonitor kernel monitor for thread safety. Will wait if the ring buffer is full. returns 0 on sucess, -1 on error. message_reader_mm dequeues a string message from the ring buffer, using the mymonitor kernel monitor for thread safety. Will wait if there is no message in the ring buffer. writes the null terminated string in buffer msg, not to exceed length len, including the null byte. returns the number of bytes written, including the null byte. message_writer_mm enqueues the string message msg on the ring buffer, using the mymonitor kernel monitor for thread safety. Will wait if there is insufficient space in the ring buffer to contain the message including null byte. if the message exceeds the complete ring buffer capacity, returns a -1 and nothing is sent. otherwise returns the number of bytes sent. Note: the ring buffer capacity as required not to return a -1 can be less then the complete size of the ring buffer, because of protocol overhead. Thread safety means that the ring buffer data structures are thread safe, and that messages in message mode are sent in their entirety, and message boundaries are preserved. HISTORY Created for csc421-211 BUGS Beta for csc421-211. Bugs will become known.
NAME mymessage - test the interprocess message system SYNOPSIS mymessage [-vm] [-r -n _read_limit_] [-s _write_sleep_ _messsages_] DESCRIPTION A thread-safe interprocess message system, using the mymessage functions. The _message_ argument is a collection of messages that is sent by one or more writer processes to one or more reader processes. When not in Message Mode, the messages are the individual characters of _message_. Each character is sent and received independently. Special digit mode is in effect when not in Message Mode. The characters 0 through 9 are sent as binary values 0 through 9. When a reader process not in Message Mode reads a binary 0, it exits. In Message Mode, _message_ is parsed on the "." character and each parsed component is a single message and is sent in its entirety. In Message Mode the "." is not sent. Special empty message mode is in effect when in Message Mode. The message "0" is sent as the empty message "". When a reader process in Message Mode reads an empty message, it exits. In Message Mode the reader prints each message on its own line; else it prints the characters without new lines. The following options are available: -m - Message Mode. -n _n_ - reader exits after reading _n_ messages, in message mode. the default is _n_=0, and the reader exits on on the special messages described above. -r - be a reader process. With not option, be a writer process. -s _n_ - writer sleeps _n_ seconds between sending. Default is 0 seconds. -v - verbose output. can be optioned multiple for more verbose output HISTORY Created for csc421-211 BUGS Beta for csc421-211. Bugs will become known.
MyMessage is almost completely done. It is the combination of a ringbuffer, to move data from process to process, and a synchronization add-on to keep stuff from breaking. Because we are moving data from process to process, we put the ringbuffer in the kernel. That way all processes can enqueue or dequeue on the same queue inside the ringbuffer data structure.
The in-kernel ringbuffer code you have completed in a previous assignment, but I have provided an implementation for mysyscalls.c (which goes in the kernel). The synchronization code is new.
Recall that we built up to a mesa monitor by building semaphores from spin-locks (you can look in the CaOS code for a code-sketch) and from semaphores to monitors (this is the code I provide in the mymonitor project). The mymonitor project code is transferred into syscalls.c so you only need to understand it.
This is the java implementation of reader-writer with the ring buffer. This code is found in the class repository at,
[repo]/class/examples/reader-writeer-javaYou can run and experiment with the code.
You will make class into the kernel for the ring buffer and the monitor. The ringbuf-sub.c and mymonitor-sub.c are your gateway to those kernel functions. The man pages explain these kernel extensions implemented by mysyscalls.c.
Because we are sending strings, not arbitrary byte sequences, it is possible to enqueue the null byte with the message, as a marker for message boundaries. This would lower the ring buffer capacity slightly. It does not seem possible not to lower the capacity, String length is information and information takes up space.
However, this runs into the problem of making sure there is another room in the buffer for the message. Worse yet, a constant stream of short messages might block a long message from ever getting sent.
The mymessage program and a few features to help you with this project.
author: burton rosenberg
created: 29 sep 2020
update: 1 oct 2020