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@lists.isocpp.org> 代表 Thiago Macieira via Std-Proposals <std-proposals@lists.isocpp.org>
发送时间: 星期四, 七月 4, 2024 4:59:09 下午
收件人: std-proposals@lists.isocpp.org <std-proposals@lists.isocpp.org>
抄送: Thiago Macieira <thiago@macieira.org>
主题: 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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals