O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to compile and run

The program can be compiled with the following command:

g++ Account.cpp main.cpp -o account.exe -std=c++17 -lpthread

If you have followed all the steps as instructed, your code should compile successfully. 

It's time to execute and observe how our program works!

Don't forget that the WITHDRAWER thread always withdraws INR 1000.00, while the DEPOSITOR thread always deposits INR 2000.00. The following output conveys this at first. The WITHDRAWER thread started withdrawing, followed by the DEPOSITOR thread that seems to have deposited the money.  

Though we started the DEPOSITOR thread first and the WITHDRAWER thread next, it looks like the OS scheduler seems to have scheduled the WITHDRAWER thread first. There is no guarantee ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required