C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::atomic::wait_and_write_back/wait_and_exchange

From: 李 秋逸 <QiuyiLi1023_at_[hidden]>
Date: Thu, 4 Jul 2024 21:28:03 +0000
Sorry for bother you. If you check the impl of 'wait' you will found there is an extra atomic load in the former code. However, I found this change is too little to effect the proformance of the binary_semaphore. So this is just a mistake.

________________________________
发件人: Std-Proposals <std-proposals-bounces_at_[hidden]> 代表 Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]>
发送时间: 星期四, 七月 4, 2024 4:59:09 下午
收件人: std-proposals_at_[hidden]rg <std-proposals_at_[hidden]>
抄送: Thiago Macieira <thiago_at_[hidden]>
主题: Re: [std-proposals] std::atomic::wait_and_write_back/wait_and_exchange

On Wednesday 3 July 2024 23:24:09 CEST 李 秋逸 via Std-Proposals wrote:
> Here is the impl in MSVC STL:
>
> //The only data member of std::binary_semaphore is atomic<unsigned char>
> _Counter void acquire() noexcept /* strengthened */ {
> for (;;) {
> unsigned char _Prev = _Counter.exchange(0);
> if (_Prev == 1) {
> break;
> }
> _Counter.wait(0, memory_order_relaxed);
> }
> }
>
> It will change to
>
> void acquire() noexcept
> {
> _Counter.wait_and_write_back(0);
> }
>
> Observely, there is less atomic calling and if​ in the function body of
> acquire.

Why do you say there's less atomic code? You've moved the implementation of
one function into another, but have not shown this produces better or safer
code.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering



--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-07-04 21:28:12