Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 11PP
Program Plan Intro

Thread counting

Program Plan:

  • Include required header file for thread and chrono seconds.
  • Define function “countingThread” with two arguments stop value pointer and count value pointer.
    • Performs “while” loop. This loop performs upto the stop value.
      • User need to wait one second using “chrono” seconds.
      • Increment the count value pointer
      • If the count value is equal to “0”, then display count value.
  • Define main function.
    • Initializes the stop value in “bool” type.
    • Initializes the count to “1”.
    • Generate thread with counting thread function, stop value and count.
    • Initializes the number to “0”.
    • Performs “do-while” loop. This loop will execute upto, the number is less than count
      • Read the number from user.
    • Assign stop count value to “true”.
    • Wait for thread to complete by using “join” function.

Blurred answer
Students have asked these similar questions
Implement a solution to the critical section problem with threads using semaphores. you must add a third counting thread which counts by 1 each time it enters its critical section to 3,000,000. Each counts to 3,000,000 for a total of 9,000,000.
In this assignment, you are provided with working code that does the following: 1. You input a sentence (containing no more than 50 characters). 2. The program will read the sentence and put it into an array of characters. 3. Then, it creates one thread for each character in the sentence. 4. The goal of the program is to capitalize each letter that has an odd index. The given program actually does this, but lacks the synchronization of the threads, so the output is not correct. You will need to provide the synchronization using mutex locks. Specifically, you are to (1) declare the mutex lock, (2) initialize the mutex lock, (3) lock and unlock the mutex lock at an appropriate location that results in the code working as expected, and (4) destroy the mutex lock. Be sure to place the mutex locks so that your program works correctly every time. Do not remove code or functions – you are to add the synchronization pieces only. When compiling using the GNU C compiler, be sure to include the…
Design a food ordering system where your python program will run two threads,   Place Order: This thread will be placing an order and inserting that into a queue. This thread places new order every 0.5 second. (hint: use time.sleep(0.5) function) Serve Order: This thread will serve the order. All you need to do is pop the order out of the queue and print it. This thread serves an order every 2 seconds. Also start this thread 1 second after place order thread is started. Pass following list as an argument to place order thread, orders = ['pizza','samosa','pasta','biryani','burger'] This problem is a producer,consumer problem where place_order thread is producing orders whereas serve_order thread is consuming the food orders. Use Queue class.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education