#include <xtd/threading/thread_pool>
#include <xtd/console>
#include <xtd/lock>
#include <xtd/random>
#include <xtd/startup>
namespace examples {
class account :
public object {
public:
explicit account(int initial) : balance(initial) {}
void do_transactions() {
for (auto i = 0; i < 100; ++i)
}
private:
int withdraw(int amount) {
if (balance < amount) return 0;
console::write_line("Balance before Withdrawal : {0}", balance);
console::write_line("Amount to Withdraw : -{0}", amount);
balance = balance - amount;
console::write_line("Balance after Withdrawal : {0}", balance);
return amount;
}
return 0;
}
int balance = 0;
};
class program {
public:
static void main() {
auto account = examples::account {1000};
for (
auto i = 0;
i < 10; ++
i)
thread_pool::queue_user_work_item({account, &account::do_transactions});
thread_pool::close();
}
};
}
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
virtual int32 next() const
Returns a nonnegative random number.
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.h:40
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.h:18
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.h:10