Shows how to use xtd::threading::interlocked class.
#include <xtd/threading/interlocked>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/random>
#include <xtd/startup>
namespace interlocked_example {
struct my_thread {
};
class my_interlocked_exchange_class {
private:
inline static int using_resource = 0;
static constexpr int num_thread_iterations = 5;
public:
static auto main() {
auto my_threads = std::array<my_thread, 10> {};
for (auto index = 0ul; index < my_threads.size(); ++index) {
my_threads[index].thread =
thread {my_thread_proc};
my_threads[index].
thread.start(my_threads[index].name);
}
for (auto index = 0ul; index < my_threads.size(); ++index)
}
static void my_thread_proc(
std::any name) {
for (auto index = 0; index < num_thread_iterations; ++index) {
}
}
static auto use_resource(
const ustring& name)->bool {
return true;
} else {
return false;
}
}
};
}
startup_(interlocked_example::my_interlocked_exchange_class::main);