Re: Text Output to Shell
vivekian wrote:
> I am working as an teaching assistant for a computer networking class
> and have been assigned to write the server side of a small networking
> application meant as an assignment for the students. The application is
> meant to fulfill the following objectives :
>
> 1. Function as the server side of the application.
> 2. When the students are developing the client side , it should guide
> them as a diagnostic tool. e.g. if they send a message and the format
> is not correct , it should let them know this and indicate the correct
> format.
>
> It is a console based application where output is text.
OK, but this has nothing to do with sending output to the shell.
The shell is program. Maybe you want to send output to the
terminal, which is different from the shell and which is something
the shell sends output to as well.
> There are
> multiple threads running within the application. Are there any
> suggestions as to how the output messages / diagnostics messages be
> displayed inorder that the different threads throwing out information
> can be seperated ? The idea is to give the students the relevant
> information without confusing them too much.
If you are using the stdio.h routines, or one of lots of other APIs,
you'll have to serialize access to library calls anyway. So, serialize
output, and print one line messages from each thread. At the beginning
of the line, but an indentifier (textual and symbolic, numeric,
indentation level, whatever) that shows what thread the message has
come from.
Since writing to the terminal (or to stdout) will sometimes block, if
you cannot tolerate blocking, you might be able to write messages into a
buffer (serializing access to the buffer, of course), then have another
thread whose job it is to consume data from the buffer and write it to
the terminal, or to stdout. Of course, your buffer may eventually
fill and cause blocking anyway, but maybe you can use an arbitrary
buffer or maybe you have a finite amount of data to write there.
Alternatively, you could use curses or similar and divide the screen
up into separate regions, then have each thread write to a separate
region.
- Logan
|