Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!