{"id":5263,"date":"2017-05-22T17:28:36","date_gmt":"2017-05-22T17:28:36","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/malicious-race-conditions\/"},"modified":"2023-06-26T12:15:37","modified_gmt":"2023-06-26T12:15:37","slug":"malicious-race-conditions","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/malicious-race-conditions\/","title":{"rendered":"Malicious Race Conditions and Data Races"},"content":{"rendered":"<p>This post is about malicious race conditions and data races. Malicious race conditions are race conditions that cause the breaking of invariants, blocking issues of threads, or lifetime issues of variables.<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;First, let me remind you what a race condition is.&nbsp;<\/p>\n<ul>\n<li><strong>Race condition: <\/strong>A race condition is a situation in which the result of an operation depends on the interleaving of certain individual operations.<\/li>\n<\/ul>\n<p>That&#8217;s fine as a starting point. A race condition can break the invariance of a program.<\/p>\n<h2>Breaking of invariants<\/h2>\n<p>In the last post&nbsp;<a href=\"https:\/\/www.modernescpp.com\/index.php\/race-condition-versus-data-race\">Race Conditions and Data Races<\/a>, I use money transfer between two accounts to show a data race. There was a benign race condition involved. There was also a malicious race condition.<\/p>\n<p>The malicious race condition breaks an invariant of the program. The invariant is, that the sum of all balances should always have the same amount. Which in our case is 200 because each account starts with 100 (1). For simplicity reasons, the unit should be euro. Neither I want to create money by transferring it, nor do I want to destroy it.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ breakingInvariant.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;atomic&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;functional&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;thread&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">struct<\/span> Account{\r\n  std<span style=\"color: #555555;\">::<\/span>atomic<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span> balance{<span style=\"color: #ff6600;\">100<\/span>};                               <span style=\"color: #0099ff; font-style: italic;\">\/\/ 1<\/span>\r\n};\r\n                                                              \r\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">transferMoney<\/span>(<span style=\"color: #007788; font-weight: bold;\">int<\/span> amount, Account<span style=\"color: #555555;\">&amp;<\/span> from, Account<span style=\"color: #555555;\">&amp;<\/span> to){\r\n  <span style=\"color: #006699; font-weight: bold;\">using<\/span> <span style=\"color: #006699; font-weight: bold;\">namespace<\/span> std<span style=\"color: #555555;\">::<\/span>chrono_literals;\r\n  <span style=\"color: #006699; font-weight: bold;\">if<\/span> (from.balance <span style=\"color: #555555;\">&gt;=<\/span> amount){\r\n    from.balance <span style=\"color: #555555;\">-=<\/span> amount;  \r\n    std<span style=\"color: #555555;\">::<\/span>this_thread<span style=\"color: #555555;\">::<\/span>sleep_for(<span style=\"color: #ff6600;\">1<\/span>ns);                           <span style=\"color: #0099ff; font-style: italic;\">\/\/ 2<\/span>\r\n    to.balance <span style=\"color: #555555;\">+=<\/span> amount;\r\n  }\r\n}\r\n\r\n <span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">printSum<\/span>(Account<span style=\"color: #555555;\">&amp;<\/span> a1, Account<span style=\"color: #555555;\">&amp;<\/span> a2){\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> (a1.balance <span style=\"color: #555555;\">+<\/span> a2.balance) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;         <span style=\"color: #0099ff; font-style: italic;\">\/\/ 3<\/span>\r\n}\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n  Account acc1;\r\n  Account acc2;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Initial sum: \"<\/span>;                          \r\n  printSum(acc1, acc2);                                        <span style=\"color: #0099ff; font-style: italic;\">\/\/ 4<\/span>\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span> thr1(transferMoney, <span style=\"color: #ff6600;\">5<\/span>, std<span style=\"color: #555555;\">::<\/span>ref(acc1), std<span style=\"color: #555555;\">::<\/span>ref(acc2));\r\n  std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span> thr2(transferMoney, <span style=\"color: #ff6600;\">13<\/span>, std<span style=\"color: #555555;\">::<\/span>ref(acc2), std<span style=\"color: #555555;\">::<\/span>ref(acc1));\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Intermediate sum: \"<\/span>;                \r\n  std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span> thr3(printSum, std<span style=\"color: #555555;\">::<\/span>ref(acc1), std<span style=\"color: #555555;\">::<\/span>ref(acc2));  <span style=\"color: #0099ff; font-style: italic;\">\/\/ 5<\/span>\r\n  \r\n  thr1.join();\r\n  thr2.join();\r\n  thr3.join();\r\n                                                               <span style=\"color: #0099ff; font-style: italic;\">\/\/ 6<\/span>\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"     acc1.balance: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> acc1.balance <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"     acc2.balance: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> acc2.balance <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Final sum: \"<\/span>;\r\n  printSum(acc1, acc2);                                        <span style=\"color: #0099ff; font-style: italic;\">\/\/ 8<\/span>\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>In the beginning, the sum of the accounts is 200 euros. (4) display the sum using <span style=\"font-family: courier new,courier;\">printSum<\/span> (3). Line (5) makes the invariant visible. Because there is a short sleep of <span style=\"font-family: courier new,courier;\">1ns<\/span> in line (2), the intermediate sum is 182 euros. In the end, all is fine. Each account has the right balance (6), and the sum is 200 euros (8).<\/p>\n<p>Here is the output of the program.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5259\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/breakingInvariant.PNG\" alt=\"breakingInvariant\" width=\"200\" height=\"121\" style=\"margin: 15px;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/breakingInvariant.PNG 350w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/breakingInvariant-300x181.png 300w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/p>\n<p>The malicious story goes on. Let&#8217;s create a deadlock by using conditions variables without a predicate.<\/p>\n<\/p>\n<h2>Blocking issues with race conditions<\/h2>\n<p>Only to make my point clear. You have to use a condition variable in combination with a predicate. For the details, read my post <a href=\"https:\/\/www.modernescpp.com\/index.php\/condition-variables\">Condition Variables<\/a>. If not, your program may become the victim of a spurious wakeup or lost wakeup.<\/p>\n<p>If you use a condition variable without a predicate, it may happen that the notifying thread sends its notification before the waiting thread is in the waiting state. Therefore, the waiting thread waits forever. That phenomenon is called a lost wake-up.<\/p>\n<p>Here is the program.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ conditionVariableBlock.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;condition_variable&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;mutex&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;thread&gt;<\/span>\r\n\r\nstd<span style=\"color: #555555;\">::<\/span>mutex mutex_;\r\nstd<span style=\"color: #555555;\">::<\/span>condition_variable condVar;\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">bool<\/span> dataReady;\r\n\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">waitingForWork<\/span>(){\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Worker: Waiting for work.\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>unique_lock<span style=\"color: #555555;\">&lt;<\/span>std<span style=\"color: #555555;\">::<\/span>mutex<span style=\"color: #555555;\">&gt;<\/span> lck(mutex_);\r\n    condVar.wait(lck);                           <span style=\"color: #0099ff; font-style: italic;\">\/\/ 3<\/span>\r\n    <span style=\"color: #0099ff; font-style: italic;\">\/\/ do the work<\/span>\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Work done.\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n}\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">setDataReady<\/span>(){\r\n\r\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Sender: Data is ready.\"<\/span>  <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n    condVar.notify_one();                        <span style=\"color: #0099ff; font-style: italic;\">\/\/ 1<\/span>\r\n\r\n}\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n  std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span> t1(setDataReady);\r\n  std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span> t2(waitingForWork);                <span style=\"color: #0099ff; font-style: italic;\">\/\/ 2<\/span>\r\n\r\n  t1.join();\r\n  t2.join();\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n  \r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The first invocations of the program work fine. The second invocation locks because the notify call (1) happens before the thread <span style=\"font-family: courier new,courier;\">t2<\/span>&nbsp;(2) is in the waiting state (3).<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5260\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/conditionVariableBlock.png\" alt=\"conditionVariableBlock\" style=\"margin: 15px;\" width=\"417\" height=\"244\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/conditionVariableBlock.png 417w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/conditionVariableBlock-300x176.png 300w\" sizes=\"auto, (max-width: 417px) 100vw, 417px\" \/><\/p>\n<p>Of course, deadlocks and livelocks are other effects of race conditions. A deadlock generally depends on the interleaving of the threads, and may sometimes happen or not. A livelock is similar to a deadlock. While a deadlock blocks, I livelock seems to make progress. The emphasis lies on seems. Think about a transaction in a transactional memory use case. Each time the transaction should be committed, a conflict happens. Therefore a rollback takes place. Here is my post about <a href=\"https:\/\/www.modernescpp.com\/index.php\/transactional-memory\">Transactional Memory<\/a>.<\/p>\n<p>Showing lifetime issues of variables is not so challenging.<\/p>\n<h2>Lifetime issues of variables<\/h2>\n<p>The recipe of a lifetime issue is quite simple. Let the created thread run in the background and you are half done. That means the creator thread will not wait until its child is done. In this case, you have to be extremely careful that the child is not using something belonging to the creator.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ lifetimeIssues.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;string&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;thread&gt;<\/span>\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n    \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"Begin:\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;            <span style=\"color: #0099ff; font-style: italic;\">\/\/ 2    <\/span>\r\n\r\n  std<span style=\"color: #555555;\">::<\/span>string mess{<span style=\"color: #cc3300;\">\"Child thread\"<\/span>};\r\n\r\n  std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span> t([<span style=\"color: #555555;\">&amp;<\/span>mess]{ std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> mess <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;});\r\n  t.detach();                                    <span style=\"color: #0099ff; font-style: italic;\">\/\/ 1<\/span>\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"End:\"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;              <span style=\"color: #0099ff; font-style: italic;\">\/\/ 3<\/span>\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>This is too simple. The thread <span style=\"font-family: courier new,courier;\">t<\/span> is using <span style=\"font-family: courier new,courier;\">std::cout<\/span> and the variable <span style=\"font-family: courier new,courier;\">mess<\/span>. Both belong to the main thread. The effect is that we don&#8217;t see the output of the child thread in the second run. Only &#8220;<span style=\"font-family: courier new,courier;\">Begin:<\/span>&#8221; (2) and <span style=\"font-family: courier new,courier;\">&#8220;End:<\/span>&#8221; (3) are displayed.&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5261\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/lifetimeIssues2.PNG\" alt=\"lifetimeIssues2\" width=\"400\" height=\"252\" style=\"margin: 15px;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/lifetimeIssues2.PNG 567w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/lifetimeIssues2-300x189.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>I want to emphasize it very explicitly. All the programs in this post are up to this point without a data race. You know it was my idea to write about race conditions and data races. They are related but different concepts.<\/p>\n<p>I can even create a data race without a race condition.<\/p>\n<h2>A data race without a race condition<\/h2>\n<p>But first, let me remind you what a data race is.<\/p>\n<ul>\n<li><strong>Data race<\/strong>: A data race is a situation in which at least two threads access a shared variable simultaneously. At least one thread tries to modify the variable.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ addMoney.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;functional&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;thread&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;vector&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">struct<\/span> Account{\r\n  <span style=\"color: #007788; font-weight: bold;\">int<\/span> balance{<span style=\"color: #ff6600;\">100<\/span>};                              <span style=\"color: #0099ff; font-style: italic;\">\/\/ 1<\/span>\r\n};\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">addMoney<\/span>(Account<span style=\"color: #555555;\">&amp;<\/span> to, <span style=\"color: #007788; font-weight: bold;\">int<\/span> amount){\r\n  to.balance <span style=\"color: #555555;\">+=<\/span> amount;                          <span style=\"color: #0099ff; font-style: italic;\">\/\/ 2<\/span>\r\n}\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>(){\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n  Account account;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>vector<span style=\"color: #555555;\">&lt;<\/span>std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span><span style=\"color: #555555;\">&gt;<\/span> vecThreads(<span style=\"color: #ff6600;\">100<\/span>);\r\n  \r\n                                                 <span style=\"color: #0099ff; font-style: italic;\">\/\/ 3<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">for<\/span> (<span style=\"color: #006699; font-weight: bold;\">auto<\/span><span style=\"color: #555555;\">&amp;<\/span> thr<span style=\"color: #555555;\">:<\/span> vecThreads) thr <span style=\"color: #555555;\">=<\/span> std<span style=\"color: #555555;\">::<\/span><span style=\"color: #006699; font-weight: bold;\">thread<\/span>( addMoney, std<span style=\"color: #555555;\">::<\/span>ref(account), <span style=\"color: #ff6600;\">50<\/span>);\r\n  \r\n  <span style=\"color: #006699; font-weight: bold;\">for<\/span> (<span style=\"color: #006699; font-weight: bold;\">auto<\/span><span style=\"color: #555555;\">&amp;<\/span> thr<span style=\"color: #555555;\">:<\/span> vecThreads) thr.join();\r\n  \r\n                                                 <span style=\"color: #0099ff; font-style: italic;\">\/\/ 4<\/span>\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"account.balance: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> account.balance <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\r\n\r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>100 threads add 50 euros (3) to the same account (1). They use the function <span style=\"font-family: courier new,courier;\">addMoney. <\/span>The critical observation is that the writing to the account is done without synchronization. Therefore we have a data race and no valid result. That is undefined behavior and the final balance (4) differs between 5000 and 5100 euros.<span style=\"font-family: courier new,courier;\"> <\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5262\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/addMoney.png\" alt=\"addMoney\" style=\"margin: 15px;\" width=\"276\" height=\"321\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/addMoney.png 276w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2017\/05\/addMoney-258x300.png 258w\" sizes=\"auto, (max-width: 276px) 100vw, 276px\" \/><\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>I often hear at concurrency conference discussions about the terms non-blocking, lock-free, and wait-free. So let me write about these terms in my <a href=\"https:\/\/www.modernescpp.com\/index.php\/blocking-and-non-blocking\">next post<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is about malicious race conditions and data races. Malicious race conditions are race conditions that cause the breaking of invariants, blocking issues of threads, or lifetime issues of variables.<\/p>\n","protected":false},"author":21,"featured_media":5259,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[366],"tags":[507,506],"class_list":["post-5263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-multithreading","tag-data-races","tag-race-conditions"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=5263"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5263\/revisions"}],"predecessor-version":[{"id":6871,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5263\/revisions\/6871"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/5259"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}