История изменений
Исправление
kvpfs,
(текущая версия)
:
#include <memory>
#include <atomic>
#include <thread>
#include <vector>
using namespace std;
struct ITC_mes {
atomic_flag f;
int data;
};
using arg_t = shared_ptr<ITC_mes>;
void thread_fn(arg_t a) {
a->data = 5;
a->f.test_and_set(memory_order_release);
}
int main() {
vector<arg_t> mes{make_shared<ITC_mes>()};
thread t(thread_fn, mes.back());
t.detach();
while (true) {
if (mes[0]->f.test(memory_order_acquire))
return mes[0]->data;
}
}
Исходная версия
kvpfs,
:
#include <memory>
#include <atomic>
#include <thread>
#include <vector>
using namespace std;
struct ITC_mes {
atomic_flag f;
int data;
};
using arg_t = shared_ptr<ITC_mes>;
void thread_fn(arg_t a)
{
a->data = 5;
a->f.test_and_set(memory_order_release);
}
int main() {
vector<arg_t> mes{make_shared<ITC_mes>()};
thread t(thread_fn, mes.back());
t.detach();
while (true) {
if (mes[0]->f.test(memory_order_acquire))
return mes[0]->data;
}
}