Design the assignment of multithreaded programming

I am the teaching assistant of OS course this semester So I was asked to design multithreaded programming for CS undergraduates with limited C programming skills

This should not be a big task, because it only needs 5% of the final score This should be something new, so students can't just download some code from the Internet

This is what I'm thinking about, a simple message queue server

I think it may be too simple, but I can't think of anything else at the moment If you were in my position, what responsibilities would you give?

Solution

Are you using UNIX? It doesn't matter. You can also use windows

Just create a named pipe

Then create four threads

One control thread, one consumer (Reader) thread and two producer (writer) threads

The producer simply sends a string to the pipeline, and then the consumer gets the string, capitalizes it or prints it out and prints it out

The control thread is used to start and stop the other three threads It requires simple commands: startproducer1, startproducer2, startconsumer, stop and close

This shows that different threads are working on their own, but are controlled by the master at the same time (know when to close, etc.)

Bonus points if you can package it as a simple GUI, or even some simple ncurses video display, so that the control display always has visibility to accept commands and display results

You can display whether you have started a producer but no consumer, and how the thread will be blocked The same as two producers, or how consumers stop no producers

Using pipes means that you don't have to rely on the external program (and all the details of setting it up, debugging it, configuring it, and supporting it)

UNIX and windows both have named pipes (but I think system calls are different, but POSIX portability may only work here...)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>