While playing, the player thread reads one word from the file, prints it, then sleeps until the next word should be displayed

While playing, the player thread reads one word from the file, prints it, then sleeps until the next word should be displayed

 

Can be implemented in C or C++

Thread 1: The player thread

While playing, the player thread reads one word from the file, prints it, then sleeps until the next word should be displayed, and so on. Each word should be displayed on a separate line of output. (Words are white-space-separated runs of characters.) At a rate of 1.0, the player should print one word per second. At a rate of -1.0, the player prints one word per second, but proceeding backwards through the file.

For this assignment, the player plays back text files, displaying one word per second at normal rate (1.0).

The player accepts the following commands:

  • LoadFile(const      char *filename) — Prepares the player to playback the file whose name is      passed in. Stops the player if currently playing.
  • Stop() —      Stops the player if currently playing.
  • Start() —      Starts the player if currently stopped.
  • Rewind() —      Sets the position of the player to time 0.
  • SeekTo(int      byteoffset) — Sets the position of the player to the closest word      boundary past the given byte offset from the start of the file.
  • SetRate(float      rate) — Sets the playback rate: 1.0 is forward at normal speed, –
  • 1.0 is      reverse, 0.5 is forward at 1/2 speed, etc.

The control threads

The control threads generate commands for the player thread. You can think of each control thread as corresponding to a separate remote control. There are two kinds of control threads. The first kind waits for keypresses, and issues commands to the player thread based on the key pressed:

  • ‘ ‘ (blank)      — toggles the player’s mode between ‘playing’ and ‘stopped’
  • ‘r’ —      rewinds the player
  • ‘s’ —      prompts the user for a time, then seeks the player to that time
  • ‘l’ —      prompts the user for a file, then loads the file into the player
  • ‘t’ —      prompts the user for a rate, then uses it to set the player’s rate

Two other control thread are “autonomous” controllers, simulating another user issuing commands. One of the autonomous controllers periodically issues a Stop() command to the player, while the other autonomous controller thread issues a Start() command every so often. Each of these autonomous threads should sleep for a random time interval of between 5 and 30 seconds before issuing each command.

Your program should implement a function for each command (Start(), Stop(), etc.). These functions will be called by the control threads to control the player. Shared, global variables for the state, rate, position, etc. of the player thread are accessed by these routines, as well as the player thread routine.

"96% of our customers have reported a 90% and above score. You might want to place an order with us."

Essay Writing Service
Affordable prices

You might be focused on looking for a cheap essay writing service instead of searching for the perfect combination of quality and affordable rates. You need to be aware that a cheap essay does not mean a good essay, as qualified authors estimate their knowledge realistically. At the same time, it is all about balance. We are proud to offer rates among the best on the market and believe every student must have access to effective writing assistance for a cost that he or she finds affordable.

Caring support 24/7

If you need a cheap paper writing service, note that we combine affordable rates with excellent customer support. Our experienced support managers professionally resolve issues that might appear during your collaboration with our service. Apply to them with questions about orders, rates, payments, and more. Contact our managers via our website or email.

Non-plagiarized papers

“Please, write my paper, making it 100% unique.” We understand how vital it is for students to be sure their paper is original and written from scratch. To us, the reputation of a reliable service that offers non-plagiarized texts is vital. We stop collaborating with authors who get caught in plagiarism to avoid confusion. Besides, our customers’ satisfaction rate says it all.

© 2022 Homeworkcrew.com provides writing and research services for limited use only. All the materials from our website should be used with proper references and in accordance with Terms & Conditions.

Scroll to Top