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
Create an application in Java that creates n (this is set at the beginning of the application not read) threads in java. The i-th thread will be named "TXAM-i". Each thread job is to insert its name 3 times into an existing ArrayList stored in the Values class given below. Create the thread class and modify the below Values class such that we ensure that the values inserted by each thread are consecutive in the array. For example, if n=3 after running each thread the array may look as: ТХАМ-2, ТХАМ-2, ТХАМ-2, ТХАМ-1, ТХАМ-1, ТХАМ-1, ТХАМ-3, ТХАМ-3, ТХАМ-3 But will never look like (values are mixed): ΤΧΑΜ-2, ΤΧAM-3, ΤΧΑΜ-1, ΤΧΑM-2, TΧΑM-3, TΧΑM-1, ΤΧAM-2, TΧΑM- 1, TXAM-3 private class Values { private ArrayList deposit; public Values () { deposit = new ArrayList(); } }
10. Write a multi-threading JAVA program having four threads:- The “Generator” thread: it takes as argument (in the constructor) aninteger N and generates an array of N integers- The “Even” thread: it takes as argument (in the constructor) an array ofintegers and counts the number of even numbers in the array- The “Odd” thread: it takes as argument (in the constructor) an array ofintegers and count the number of odd numbers in the array- The main thread:o it asks the user to enter an integer No Then, it runs the “Generator” thread to create an array of integersand waits the end of “Generator”o Then, it run “Even” and “Odd” to count the number of even andodd numbers in the generated arrayo Finally, it prints if there is more even or odd numbersNote: the main thread should wait the end of “Even” and “Odd”threads before printing the final result.
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…
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