<h1>Backport of <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="403892040" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/10891" data-hovercard-type="pull_request" data-hovercard-url="/RIOT-OS/RIOT/pull/10891/hovercard" href="https://github.com/RIOT-OS/RIOT/pull/10891">#10891</a></h1>
<h3>Contribution description</h3>
<pre><code>Error case:
1. thread_yield_higher() stores the thread's ucontext
2. creates an "isr ucontext" for isr_thread_yield, switches to it

Case 1: no signals are pending, continues in isr_thread_yield()
3a. sched_run is called
4a. return to sched_active_thread ucontext

Case 2: signals pending (the crashing scenario), continues in native_irq_handler()
3b. handles signals
4b. if sched_context_switch_request is set, call sched_run
5b. return to sched_active_thread ucontext

4b misses the call to sched_run(), leading to a possible return into a
non-ready thread.
</code></pre>
<p><span class="issue-keyword tooltipped tooltipped-se" aria-label="This pull request closes issue #10881.">Fixes</span> <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="403541711" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/10881" data-hovercard-type="issue" data-hovercard-url="/RIOT-OS/RIOT/issues/10881/hovercard" href="https://github.com/RIOT-OS/RIOT/issues/10881">#10881</a>.</p>
<h3>Testing procedure</h3>
<p>See <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="403541711" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/10881" data-hovercard-type="issue" data-hovercard-url="/RIOT-OS/RIOT/issues/10881/hovercard" href="https://github.com/RIOT-OS/RIOT/issues/10881">#10881</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="404900394" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/10908" data-hovercard-type="pull_request" data-hovercard-url="/RIOT-OS/RIOT/pull/10908/hovercard" href="https://github.com/RIOT-OS/RIOT/pull/10908">#10908</a></p>
<h3>Issues/PRs references</h3>
<p><span class="issue-keyword tooltipped tooltipped-se" aria-label="This pull request closes issue #10881.">Fixes</span> <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="403541711" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/10881" data-hovercard-type="issue" data-hovercard-url="/RIOT-OS/RIOT/issues/10881/hovercard" href="https://github.com/RIOT-OS/RIOT/issues/10881">#10881</a>.<br>
<span class="issue-keyword tooltipped tooltipped-se" aria-label="This pull request closes issue #6123.">Fixes</span> <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="189447092" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/6123" data-hovercard-type="issue" data-hovercard-url="/RIOT-OS/RIOT/issues/6123/hovercard" href="https://github.com/RIOT-OS/RIOT/issues/6123">#6123</a>.</p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/RIOT-OS/RIOT/pull/10921'>https://github.com/RIOT-OS/RIOT/pull/10921</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>cpu/native: fix race condition in thread_yield_higher()</li>
  <li>core/msg: add assert for problem identified in #10881</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/10921/files#diff-0">core/msg.c</a>
    (1)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/10921/files#diff-1">cpu/native/native_cpu.c</a>
    (5)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/10921.patch'>https://github.com/RIOT-OS/RIOT/pull/10921.patch</a></li>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/10921.diff'>https://github.com/RIOT-OS/RIOT/pull/10921.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/10921">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AEn7YMa5JOVxo8Z6rpXU5mPogTfNRlo3ks5vJFwGgaJpZM4aehPD">mute the thread</a>.<img src="https://github.com/notifications/beacon/AEn7YHeASD0IDt2W1XTRXxQA6XzGYVcWks5vJFwGgaJpZM4aehPD.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/RIOT-OS/RIOT","title":"RIOT-OS/RIOT","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/RIOT-OS/RIOT"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"cpu/native: fix race in thread_yield_higher() [backport 2019.01] (#10921)"}],"action":{"name":"View Pull Request","url":"https://github.com/RIOT-OS/RIOT/pull/10921"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/10921",
"url": "https://github.com/RIOT-OS/RIOT/pull/10921",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>