- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究 Michael & Scott 的无锁队列算法,并尝试用 C++ 实现它。
但是我在代码中产生了竞争,并且认为算法中可能存在竞争。
我在这里阅读了这篇论文: Simple, Fast, and Practical Non-Blocking and BlockingConcurrent Queue Algorithms原始Dequeue伪代码如下:
dequeue(Q: pointer to queue_t, pvalue: pointer to data type): boolean
D1: loop // Keep trying until Dequeue is done
D2: head = Q->Head // Read Head
D3: tail = Q->Tail // Read Tail
D4: next = head.ptr->next // Read Head.ptr->next
D5: if head == Q->Head // Are head, tail, and next consistent?
D6: if head.ptr == tail.ptr // Is queue empty or Tail falling behind?
D7: if next.ptr == NULL // Is queue empty?
D8: return FALSE // Queue is empty, couldn't dequeue
D9: endif
// Tail is falling behind. Try to advance it
D10: CAS(&Q->Tail, tail, <next.ptr, tail.count+1>)
D11: else // No need to deal with Tail
// Read value before CAS
// Otherwise, another dequeue might free the next node
D12: *pvalue = next.ptr->value
// Try to swing Head to the next node
D13: if CAS(&Q->Head, head, <next.ptr, head.count+1>)
D14: break // Dequeue is done. Exit loop
D15: endif
D16: endif
D17: endif
D18: endloop
D19: free(head.ptr) // It is safe now to free the old node
D20: return TRUE // Queue was not empty, dequeue succeeded
在我看来,比赛是这样的:
head.ptr->next
,但由于 head.ptr
已被线程 1 释放,因此发生崩溃。 我的 C++ 代码确实总是在线程 1 的 D4 处崩溃。
有人可以指出我的错误并给出一些解释吗?
最佳答案
谢谢,非常有趣的话题!这看起来确实像一个 bug,但该论文的一位作者断言,他们的 free() 不是我们所使用的普通 free(),而是一些神奇的 free(),所以不存在 bug。太棒了。
希望没有人在没有经过彻底分析的情况下将其投入生产。
关于data-structures - 解释 Michael & Scott 无锁队列算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40818465/
我正在尝试理解/运行 Michael Neilsen 的神经网络和深度学习第 2 章中关于反向传播的代码:http://neuralnetworksanddeeplearning.com/chap2.
我正在尝试建立一个学习 mnist 数字的网络,正如 Michael Nielsen 在他的书 (http://neuralnetworksanddeeplearning.com/chap1.html
这是我在使用 bundle exec rspec spec/requests/static_pages_spec.rb 时遇到的错误。 我已经包含了 gem 测试单元。 请帮助我,我是 Rails 的
我正在研究 Michael & Scott 的无锁队列算法,并尝试用 C++ 实现它。 但是我在代码中产生了竞争,并且认为算法中可能存在竞争。 我在这里阅读了这篇论文: Simple, Fast, a
我在尝试实现 Hartl 的 Ruby on Rails 教程中的示例应用程序时遇到了一个奇怪的问题。 当我删除微博时,会发生以下情况: 微博被删除。 用户也会被删除。 定向至“注册”页面。 只应该发
我尝试使用 Google 网站管理员工具重新抓取网站,但没有成功。 有谁知道为什么 Google 上的链接可能会显示“halalgems.com”,但会重定向到另一个网站? 描述也不正确。 最佳答案
阅读 Hartl 的教程,地址为 list 10.42 在 microposts Controller 中,我们有 def create @micropost = current_user
我已经完成了本教程,但自第 7 节制作注册表单以来,我在 CSS 渲染方面遇到了一些小问题。这就是我得到的: 它应该是这样的: 这是相关的 CSS: @mixin box_sizing { -mo
我正在关注 Michael Hartl 教程并在 Listing 10.14 之后,他说 There is one subtlety, though: on failed micropost subm
我正在写关于我在完成 Michael Hartl 的 Ruby on Rails 教程时遇到的问题。问题是 css 不会更改用于密码确认的输入字段的外观。所有其他输入字段的外观都受 css 规则的影响
我正在编写 Michael Hartl 的教程。我在第 6 章。我要进行用户验证。下面的代码是我被告知要使用的代码,但它不起作用。我收到错误消息 syntax error, unexpected en
我正在使用 libcds他们实现了 Michael Hash Map 和 Split order list。 根据我从文档中收集到的信息,我是如何实现它们的: 包括: #include #inclu
我正在学习 Michael Hartl 的 Ruby on Rails 教程,我在 third exercise of chapter 5 方面遇到了一些麻烦.我已经创建了 application_h
我没有从 Hartl 的 Rails 教程中得到以下练习的答案: By replacing the question marks in Listing 4.10 with the appropriat
我在第五章的最后做练习。我应该测试链接是否转到正确的页面。这是我的测试代码。 require 'spec_helper' describe "LayoutLinks" do it "shoul
我正在学习 Michael Hartl 的 Ruby On Rails 3 教程,并使用 Capybara 进行集成规范。到目前为止的集成规范如下 require 'spec_helper' desc
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
在本教程的第 10 章中,我正在更改微博的 CSS 以使其看起来不同。但是它们不会在我的本地服务器上更新。我尝试重新启动服务器并重置并重新填充数据库,但仍然没有成功。为什么会这样? 自定义 CSS 文
示例代码: assert_select 'div#' assert_select 'div.' 这会产生:弃用警告:由于无效的 css 选择器,断言未运行。 ] 16% 时间:00:00:01,预计到
我正在学习 Hartl 的 Ruby 教程。我在第5章的开头。 说明是通过 添加图像('rails.png') 主页:app/views/static_pages/home.html.e
我是一名优秀的程序员,十分优秀!