#include <xtd/threading/interlocked>
#include <xtd/threading/thread>
#include <xtd/console>
#include <xtd/random>
#include <xtd/startup>
namespace interlocked_example {
struct my_thread {
string name;
};
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].name = string::format("Thread{}", index + 1);
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 string& name)->bool {
return true;
} else {
return false;
}
}
};
}
startup_(interlocked_example::my_interlocked_exchange_class::main);
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.hpp:44
static type_t exchange(type_t &location, type_t value)
Sets a variable of the specified type type_t to a specified value and returns the original value,...
Definition interlocked.hpp:133
Creates and controls a thread, sets its priority, and gets its status.
Definition thread.hpp:45
thread(const xtd::threading::parameterized_thread_start &start)
Initializes a new instance of the xtd::threading::thread class, specifying a delegate that allows an ...
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
void join()
Blocks the calling thread until this thread object terminates, while continuing to perform standard C...
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:167
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
The xtd::threading namespace provides classes and interfaces that enable multithreaded programming....
Definition abandoned_mutex_exception.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8