Question

In: Computer Science

Create a simple C++ application that will exhibit concurrencyconcepts. Your application should create two threads...

Create a simple C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0. For your created code, provide a detailed analysis of appropriate concepts that could impact your application. Specifically, address:

  • Performance issues with concurrency

  • Vulnerabilities exhibited with use of strings

  • Security of the data types exhibited.

Solutions

Expert Solution

Points to consider:

  1. Following is the code which counts from 0 to 20 and other thread function that counts from 20 down to 0
  2. In the below program, there is the use of multithreading.

Code

#include
#include
using namespace std;
int count = 0;
void countDown()
{
   while(count > 0)
   {
       count--;
       cout<<"Count Down: "<    }
}
void countUp()
{
   while(count < 20)
   {
       count++;
       cout<<"Count Up: "<    }
}
int main()
{
   thread t1(countUp);
   thread t2(countDown);
   t1.join();
   t2.join();
}


1. Performance issues with concurrency.
With the concurrency, there could be sometimes a reduction in performance because there could be multiple processes that we are trying to execute on the same core, there are so many context switches involved. Thus there could be a reduction in the speed of the task.

2. Vulnerabilities exhibited with the use of strings

As we can append any length of characters to the strings, thus there is a vulnerability with the strings. Thus we should define the strings with a specific number of characters. So that there will be no append of characters to the string.

3. As the data can be used by multiple threads in the case of multithreading thus there is a need to make sure that the data type is not changed by any of the function and other function who is using the same data type is considering it as other data type.


Related Solutions

Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
C++Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
C++ application:Create a C++ application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.For your created code, provide a written analysis of appropriate concepts that could impact your application.Please Specifically, Address: Performance Issues with Concurrency Vulnerabilities Exhibited with use of Strings and Security of the Data Types used.
Create a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters.
JAVACreate a Java application that will exhibit concurrency concepts. Your application should create two threads that will act as counters. One thread should count up to 20. Once thread one reaches 20, then a second thread should be used to count down to 0.
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
Create a python application that inputs, processes and stores student data. Specifications: 1. Your application should...
Create a python application that inputs, processes and stores student data. Specifications: 1. Your application should be able to accept Student data from the user and add the information in a file type of your choice. 2. your application is a menu driven and allow the user to choose from the following menu Menu: 1 – Add students to file 2 – print all the student information 3 – print specific student information using studentID 4 – Exit the program...
use C++ to create a function to calculate it. My requirements are very simple: function should...
use C++ to create a function to calculate it. My requirements are very simple: function should be general to deal with any size matrices. That's all.
Create a Windows application in C# that can be used to change the form color. Your...
Create a Windows application in C# that can be used to change the form color. Your form background color should initially be blue. Provide at least two buttons with two different color choices and a Reset option. Change the font style and size on buttons. Align the buttons so that they are in the center of the form. The color choice buttons should be the same size. Add event handlers for the buttons so that when the user click the...
You will design and create your own GUI application for the Bank project. This project should...
You will design and create your own GUI application for the Bank project. This project should be designed and written by Java programming. The requirements of the program: 1. The program will be best implemented as a multi-file program for each class. 2. The parameters and return types of each function and class member should be decided in advance. You may need to add more member variables and functions to the classes than those listed below. Also, you can throws...
Python Create a tkinter GUI application that has two buttons on it. The first button should...
Python Create a tkinter GUI application that has two buttons on it. The first button should have in red text the word "Red" on it and the second button should have in blue text the word "Blue" on it. When the red button is clicked you should change the background color of the application window to red and when the blue button is pressed you should change the background color of the application window to blue. You should place your...
C# Simple Text File Merging Application - The idea is to merge two text files located...
C# Simple Text File Merging Application - The idea is to merge two text files located in the same folder to create a new txt file (also in the same folder). I have the idea, and I can merge the two txt files together, however I would like to have an empty line between the two files. How would I implement this in the code below? if (File.Exists(fileNameWithPath1)) { try { string[] file1 = File.ReadAllLines(fileNameWithPath1); string[] file2 = File.ReadAllLines(fileNameWithPath2); //dump...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT