Пространства имён
Варианты
Действия

std::atomic_thread_fence

Материал из cppreference.com

Заголовочный файл <atomic>
extern "C" void atomic_thread_fence( std::memory_order order );
(начиная с C++11)
Устанавливает памяти синхронизации упорядочения неатомической и расслабленной атомного доступа, в соответствии с инструкциями order, не связанные атомарные операции. Например, все без атомной и расслабленной атомного магазинов, которые происходят до std::memory_order_release забор в потоке будут синхронизированы с неатомической и расслабленной атомного грузы из того же места, сделанные в потоке B после std::memory_order_acquire забором.
Original:
Establishes memory synchronization ordering of non-atomic and relaxed atomic accesses, as instructed by order, without an associated atomic operation. For example, all non-atomic and relaxed atomic stores that happen before a std::memory_order_release fence in thread A will be synchronized with non-atomic and relaxed atomic loads from the same locations made in thread B after an std::memory_order_acquire fence.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] Параметры

order -
памяти упорядочения выполняться с помощью этого забора
Original:
the memory ordering executed by this fence
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Возвращаемое значение

(Нет)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Исключения

noexcept-спецификация:  
noexcept
  (начиная с C++11)

[править] Примеры

Scan an array of mailboxes, and process only the ones intended for us, without unnecessary synchronization.

const int num_mailboxes = 32;
std::atomic<int> mailbox[num_mailboxes];
 
// The writer threads update non-atomic shared data and then update mailbox[i] as follows
 std::atomic_store_explicit(&mailbox[i], std::memory_order_release);
 
// Reader thread needs to check all mailbox[i], but only needs to sync with one
 for (int i = 0; i < num_mailboxes; ++i) {
    if (std::atomic_load_explicit(&mailbox[i],  std::memory_order_relaxed) == my_id) {
        std::atomic_thread_fence(std::memory_order_acquire); // synchronize with just one writer
        do_work(i); // guaranteed to observe everything done in the writer thread before
                    // the atomic_store_explicit()
    }
 }


[править] См. также

определяет памяти заказе ограничений для данного атомарные операции
Original:
defines memory ordering constraints for the given atomic operation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(определение типа) [edit]
забор между нитью и обработчик сигнала выполняется в том же потоке
Original:
fence between a thread and a signal handler executed in the same thread
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(функция) [edit]
C документация для atomic_thread_fence