V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
XIIPanda
V2EX  ›  C++

C++菜鸡关于 C++多线程的疑问

  •  
  •   XIIPanda · Nov 15, 2023 · 1974 views
    This topic created in 903 days ago, the information mentioned may be changed or developed.
    最近看一个关于 C++无锁窃取队列的项目,项目地址为: https://github.com/ConorWilliams/ConcurrentDeque/tree/main ,在项目代码里面 RingBuff 的 store 操作使用了 std::move ,在扩容期间,如果有窃取者线程进行 steal()操作且旧的 RingBuff 的 t 索引的任务已经被移动到新的 RingBuff ,那么窃取者线程获取的任务就是一个已经被移动了的任务,如果 steal()中的_top.compare_exchange_strong(t, t + 1, seq_cst, relaxed)执行成功,是不是就意味着出现了任务丢失的情况?
    2 replies    2023-11-15 20:08:52 +08:00
    misdake
        1
    misdake  
       Nov 15, 2023 via Android   ❤️ 1
    resize 的实现是循环 ppt->store(i, load(i)),load 得到的是复制,move 了也没问题,不会修改原值
    XIIPanda
        2
    XIIPanda  
    OP
       Nov 15, 2023
    @misdake #1 懂了,谢谢大佬
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3206 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 13:27 · PVG 21:27 · LAX 06:27 · JFK 09:27
    ♥ Do have faith in what you're doing.