Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What are the: Performance issues with concurrency Vulnerabilities exhibited with use of strings Security of the data types exhibited. For the following code. Please explain,

What are the:

  • Performance issues with concurrency
  • Vulnerabilities exhibited with use of strings
  • Security of the data types exhibited.

For the following code. Please explain, having trouble with this topic. The code uses threads to count up to 20 and when it finishes the second thread will count down using the same "counter" variable.

#include  #include  #include  #include  using namespace std; using namespace chrono; using namespace this_thread; int counter = 0; //global variable condition_variable cv; //used to "pause" the second thread mutex m; void add() { while (counter <= 20) { cout << "Counting up - " << counter++ << endl; sleep_for(seconds(1)); //consoles waits a second before moving on } cv.notify_one(); } void subtract() { unique_lock lock(m); cv.wait(lock); while (counter > 0) { cout << "Counting down - " << counter-- << endl; sleep_for(seconds(1)); } } int main() { thread t1(add); thread t2(subtract); t1.join(); t2.join(); system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions