For purposes of loop progress, does “atomic operation” include fences?

C++ has a “forward progress” requirement for loops:

(6.9.2.3p1) The implementation may assume that any thread will eventually do one
of the following:

  1. terminate,
  2. invoke the function std​::​this_thread​::​yield ([thread.thread.this]),
  3. make a call to a library I/O function,
  4. perform an access through a volatile glvalue,
  5. perform a synchronization operation or an atomic operation, or
  6. continue execution of a trivial infinite loop ([stmt.iter.general]). [Added in C++23]

So an infinite loop that doesn’t do any of these things (and doesn’t meet the definition of a “trivial infinite loop”) causes undefined behavior.

For purposes of item 5, is a fence considered to be an “synchronization operation or atomic operation”? If we have a non-trivial infinite loop whose body contains an atomic_signal_fence() or atomic_thread_fence() but no other side effects, does this cause undefined behavior?

I don’t think there’s an explicit definition or exhaustive list of “atomic operations” anywhere in the standard. atomics.fences describes them as “synchronization primitives” instead, and arguably it doesn’t make sense for fences to count as observable effects here, because they don’t actually have any observable effects of their own. On the other hand, atomics.order p4, in another context, speaks of a total order on “all memory_order​::​seq_cst operations, including fences”, suggesting that they are considered “operations”.

Bonus question: does it make a difference if the fence has memory_order_relaxed ordering, which is explicitly defined as having no effect?

gcc and clang appear to differ here. Given code like

bool b = true;
while (b) {
   std::atomic_signal_fence(std::memory_order_relaxed);
}

clang will delete the entire loop, and indeed emit no code at all for the function, which is its typical behavior when a function unconditionally causes UB if called. Try on godbolt.

On the other hand, gcc will emit an infinite empty loop, even though it will happily delete such loops without a fence.

More elaborate example on godbolt.

The same thing happens for other memory orders and for atomic_thread_fence (in the latter case, gcc emits an infinite loop with a barrier instruction.)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật