<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>unifa_tech</author_name>
  <author_url>https://blog.hatena.ne.jp/unifa_tech/</author_url>
  <blog_title>ユニファ開発者ブログ</blog_title>
  <blog_url>https://tech.unifa-e.com/</blog_url>
  <categories>
    <anon>スレッド</anon>
    <anon>並列化</anon>
  </categories>
  <description>こんにちは、ヘルスケア事業部のちょうです。今日は並列プログラミングによくある間違うコード及びその原因について共有したいと思います。 まずはコード（抜粋、C言語） int a = 0; bool f = false; void cpu0() { a = 1; // 1 f = true; // 2 } void cpu1() { while(!f); // 3 printf(&quot;%d\n&quot;, a); // 4 } 関数cpu0とcpu1が別々のスレッドで実行されると、結果がどうなるでしょう。 1？もちろんそのはずですが、100回やると、たまに0も出るかもしれません。</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Ftech.unifa-e.com%2Fentry%2F2018%2F07%2F24%2F120258&quot; title=&quot;なぜ違う値を見たのかーー並列実行におけるCPUの動作 - ユニファ開発者ブログ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2018-07-24 12:02:58</published>
  <title>なぜ違う値を見たのかーー並列実行におけるCPUの動作</title>
  <type>rich</type>
  <url>https://tech.unifa-e.com/entry/2018/07/24/120258</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
