У меня есть работа, которая должна быть выполнена на определенном ядре. Для этого я создал ветку и назначил его этому ядро. Теперь я пытаюсь выяснить общий способ дать ему работу и получить результаты этой работы.
// Imagine SPSCQueue is a thread-safe SPSC queue that uses atomics to
// synchronize its internals, such as moodycamel::ReaderWriterQueue
SPSCQueue workQueue{};
SPSCQueue resultQueue{};
void thread1() {
int myInt1{3};
int myInt2{7};
while(1) {
// Queue a function to modify the variables.
workQueue.enqueue([&]() {
myInt1 += myInt2;
myInt2 += myInt1;
});
// Wait for the work to be done on the other core.
bool result{};
resultQueue.wait_dequeue(result);
if (result) {
// Question: Are the writes observable here?
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79765645/how-do-you-know-if-non-atomic-writes-to-variables-will-be-observable-cross-core[/url]
У меня есть работа, которая должна быть выполнена на определенном ядре. Для этого я создал ветку и назначил его этому ядро. Теперь я пытаюсь выяснить общий способ дать ему работу и получить результаты этой работы.[code]// Imagine SPSCQueue is a thread-safe SPSC queue that uses atomics to // synchronize its internals, such as moodycamel::ReaderWriterQueue SPSCQueue workQueue{}; SPSCQueue resultQueue{};
void thread1() { int myInt1{3}; int myInt2{7};
while(1) { // Queue a function to modify the variables. workQueue.enqueue([&]() { myInt1 += myInt2; myInt2 += myInt1; });
// Wait for the work to be done on the other core. bool result{}; resultQueue.wait_dequeue(result); if (result) { // Question: Are the writes observable here? std::cout