<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://xinu.cs.mu.edu/index.php?action=history&amp;feed=atom&amp;title=Preemptive_multitasking</id>
	<title>Preemptive multitasking - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://xinu.cs.mu.edu/index.php?action=history&amp;feed=atom&amp;title=Preemptive_multitasking"/>
	<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;action=history"/>
	<updated>2026-06-15T16:11:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4081&amp;oldid=prev</id>
		<title>Ebiggers at 01:57, 12 September 2013</title>
		<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4081&amp;oldid=prev"/>
		<updated>2013-09-12T01:57:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 01:57, 12 September 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l5&quot; &gt;Line 5:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Embedded Xinu supports multiple threads, but only one can execute at a time.  A '''thread context''' refers to the saved state of a thread, primarily CPU registers.  Embedded Xinu platforms must implement two functions to allow creating new threads and switching between threads using their thread contexts:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Embedded Xinu supports multiple threads, but only one can execute at a time.  A '''thread context''' refers to the saved state of a thread, primarily CPU registers.  Embedded Xinu platforms must implement two functions to allow creating new threads and switching between threads using their thread contexts:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt;, which is responsible for setting up the stack of a new thread to include an initial thread context and procedure arguments.  This routine is typically implemented in C.  It is called internally by &amp;lt;code&amp;gt;create()&amp;lt;/code&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt;, which is responsible for setting up the stack of a new thread to include an initial thread context and procedure arguments.  This routine is typically implemented in C.  It is called internally by &amp;lt;code&amp;gt;create()&amp;lt;/code&amp;gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;, located in {{SourceFile|system/create.c}}.  For an example, see {{SourceFile|system/arch/mips/arch_setup_stack.c}}&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, which is responsible for switching between threads.  More specifically, this routine must save the thread context of the current thread and restore the thread context of the new thread.  This routine is always implemented in assembly language.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, which is responsible for switching between threads.  More specifically, this routine must save the thread context of the current thread and restore the thread context of the new thread.  This routine is always implemented in assembly language&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;.  For an example, see {{SourceFile|system/arch/mips/ctxsw.S}}&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since different CPU architectures use different registers and calling conventions,&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since different CPU architectures use different registers and calling conventions,&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l12&quot; &gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that since thread contexts are created in both &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, these two routines must create contexts that are compatible, at least to the extent that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; can either start a new thread or resume an existing thread.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that since thread contexts are created in both &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, these two routines must create contexts that are compatible, at least to the extent that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; can either start a new thread or resume an existing thread.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;See &lt;/del&gt;[[&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Preemptive_multitasking_&lt;/del&gt;(ARM)&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;|&lt;/del&gt;Preemptive multitasking (&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;ARM&lt;/del&gt;)]] &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;for an example.&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Other articles describe this in more detail for specific architectures:&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;[[&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Preemptive multitasking &lt;/ins&gt;(ARM)&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;* [[&lt;/ins&gt;Preemptive multitasking (&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;MIPS&lt;/ins&gt;)]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Preemption ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Preemption ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Preemption occurs when the timer interrupt occurs and Embedded Xinu attempts to reschedule the currently executing thread, which results in a call to &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, described above, that may switch to a different thread context.  (We say ''may'' because the code is written such that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; is called when the same thread is rescheduled to itself, in which case &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; restores the saved context immediately and is a no-op.)  The means of generating a timer interrupt is platform-dependent and may even differ among platforms that share the same CPU architecture.  For an example, see [[BCM2835 System Timer]], which is used in the [[Raspberry Pi]], an ARM-based platform.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Preemption occurs when the timer interrupt occurs and Embedded Xinu attempts to reschedule the currently executing thread, which results in a call to &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, described above, that may switch to a different thread context.  (We say ''may'' because the code is written such that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; is called when the same thread is rescheduled to itself, in which case &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; restores the saved context immediately and is a no-op.)  The means of generating a timer interrupt is platform-dependent and may even differ among platforms that share the same CPU architecture.  For an example, see [[BCM2835 System Timer]], which is used in the [[Raspberry Pi]], an ARM-based platform.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ebiggers</name></author>
		
	</entry>
	<entry>
		<id>https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4038&amp;oldid=prev</id>
		<title>Ebiggers: arch_setup_stack():  Note called by create()</title>
		<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4038&amp;oldid=prev"/>
		<updated>2013-09-08T15:12:10Z</updated>

		<summary type="html">&lt;p&gt;arch_setup_stack():  Note called by create()&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 15:12, 8 September 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l5&quot; &gt;Line 5:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Embedded Xinu supports multiple threads, but only one can execute at a time.  A '''thread context''' refers to the saved state of a thread, primarily CPU registers.  Embedded Xinu platforms must implement two functions to allow creating new threads and switching between threads using their thread contexts:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Embedded Xinu supports multiple threads, but only one can execute at a time.  A '''thread context''' refers to the saved state of a thread, primarily CPU registers.  Embedded Xinu platforms must implement two functions to allow creating new threads and switching between threads using their thread contexts:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt;, which is responsible for setting up the stack of a new thread to include an initial thread context and procedure arguments.  This routine is typically implemented in C.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt;, which is responsible for setting up the stack of a new thread to include an initial thread context and procedure arguments.  This routine is typically implemented in C&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;.  It is called internally by &amp;lt;code&amp;gt;create()&amp;lt;/code&amp;gt;&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, which is responsible for switching between threads.  More specifically, this routine must save the thread context of the current thread and restore the thread context of the new thread.  This routine is always implemented in assembly language.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, which is responsible for switching between threads.  More specifically, this routine must save the thread context of the current thread and restore the thread context of the new thread.  This routine is always implemented in assembly language.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ebiggers</name></author>
		
	</entry>
	<entry>
		<id>https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4037&amp;oldid=prev</id>
		<title>Ebiggers: Adjust link</title>
		<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4037&amp;oldid=prev"/>
		<updated>2013-09-08T15:11:15Z</updated>

		<summary type="html">&lt;p&gt;Adjust link&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 15:11, 8 September 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l12&quot; &gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that since thread contexts are created in both &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, these two routines must create contexts that are compatible, at least to the extent that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; can either start a new thread or resume an existing thread.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that since thread contexts are created in both &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, these two routines must create contexts that are compatible, at least to the extent that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; can either start a new thread or resume an existing thread.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [[Preemptive_multitasking_(ARM)]] for an example.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;See [[Preemptive_multitasking_&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;(ARM)|Preemptive multitasking &lt;/ins&gt;(ARM)]] for an example.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Preemption ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Preemption ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Preemption occurs when the timer interrupt occurs and Embedded Xinu attempts to reschedule the currently executing thread, which results in a call to &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, described above, that may switch to a different thread context.  (We say ''may'' because the code is written such that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; is called when the same thread is rescheduled to itself, in which case &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; restores the saved context immediately and is a no-op.)  The means of generating a timer interrupt is platform-dependent and may even differ among platforms that share the same CPU architecture.  For an example, see [[BCM2835 System Timer]], which is used in the [[Raspberry Pi]], an ARM-based platform.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Preemption occurs when the timer interrupt occurs and Embedded Xinu attempts to reschedule the currently executing thread, which results in a call to &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, described above, that may switch to a different thread context.  (We say ''may'' because the code is written such that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; is called when the same thread is rescheduled to itself, in which case &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; restores the saved context immediately and is a no-op.)  The means of generating a timer interrupt is platform-dependent and may even differ among platforms that share the same CPU architecture.  For an example, see [[BCM2835 System Timer]], which is used in the [[Raspberry Pi]], an ARM-based platform.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ebiggers</name></author>
		
	</entry>
	<entry>
		<id>https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4034&amp;oldid=prev</id>
		<title>Ebiggers: Created page</title>
		<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=Preemptive_multitasking&amp;diff=4034&amp;oldid=prev"/>
		<updated>2013-09-08T14:58:08Z</updated>

		<summary type="html">&lt;p&gt;Created page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Like virtually all modern operating systems, [[Embedded Xinu]] supports '''preemptive multitasking''', which makes it appear that multiple threads are executing at the same time on the same processor.  Support for preemptive multitasking consists of support for multiple threads combined with a preemption mechanism.&lt;br /&gt;
&lt;br /&gt;
== Multiple threads  ==&lt;br /&gt;
&lt;br /&gt;
Embedded Xinu supports multiple threads, but only one can execute at a time.  A '''thread context''' refers to the saved state of a thread, primarily CPU registers.  Embedded Xinu platforms must implement two functions to allow creating new threads and switching between threads using their thread contexts:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt;, which is responsible for setting up the stack of a new thread to include an initial thread context and procedure arguments.  This routine is typically implemented in C.&lt;br /&gt;
* &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, which is responsible for switching between threads.  More specifically, this routine must save the thread context of the current thread and restore the thread context of the new thread.  This routine is always implemented in assembly language.&lt;br /&gt;
&lt;br /&gt;
Since different CPU architectures use different registers and calling conventions,&lt;br /&gt;
the size and format of a thread context varies depending on the CPU architecture.&lt;br /&gt;
Note that since thread contexts are created in both &amp;lt;code&amp;gt;arch_setup_stack()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, these two routines must create contexts that are compatible, at least to the extent that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; can either start a new thread or resume an existing thread.&lt;br /&gt;
&lt;br /&gt;
See [[Preemptive_multitasking_(ARM)]] for an example.&lt;br /&gt;
&lt;br /&gt;
== Preemption ==&lt;br /&gt;
&lt;br /&gt;
Preemption occurs when the timer interrupt occurs and Embedded Xinu attempts to reschedule the currently executing thread, which results in a call to &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt;, described above, that may switch to a different thread context.  (We say ''may'' because the code is written such that &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; is called when the same thread is rescheduled to itself, in which case &amp;lt;code&amp;gt;ctxsw()&amp;lt;/code&amp;gt; restores the saved context immediately and is a no-op.)  The means of generating a timer interrupt is platform-dependent and may even differ among platforms that share the same CPU architecture.  For an example, see [[BCM2835 System Timer]], which is used in the [[Raspberry Pi]], an ARM-based platform.&lt;/div&gt;</summary>
		<author><name>Ebiggers</name></author>
		
	</entry>
</feed>