Thread context switch Vs. process context switch












93















Could any one tell me what is exactly done in both situations? What is the main cost each of them?










share|improve this question




















  • 1





    This maybe can help linfo.org/context_switch.html

    – Dawid Drozd
    Jan 14 '14 at 18:32
















93















Could any one tell me what is exactly done in both situations? What is the main cost each of them?










share|improve this question




















  • 1





    This maybe can help linfo.org/context_switch.html

    – Dawid Drozd
    Jan 14 '14 at 18:32














93












93








93


71






Could any one tell me what is exactly done in both situations? What is the main cost each of them?










share|improve this question
















Could any one tell me what is exactly done in both situations? What is the main cost each of them?







multithreading process context-switch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 16:31









Guy Avraham

1,48222031




1,48222031










asked Mar 26 '11 at 3:07









LeonLeon

2,80083647




2,80083647








  • 1





    This maybe can help linfo.org/context_switch.html

    – Dawid Drozd
    Jan 14 '14 at 18:32














  • 1





    This maybe can help linfo.org/context_switch.html

    – Dawid Drozd
    Jan 14 '14 at 18:32








1




1





This maybe can help linfo.org/context_switch.html

– Dawid Drozd
Jan 14 '14 at 18:32





This maybe can help linfo.org/context_switch.html

– Dawid Drozd
Jan 14 '14 at 18:32












8 Answers
8






active

oldest

votes


















163














The main distinction between a thread switch and a process switch is that during a thread switch, the virtual memory space remains the same, while it does not during a process switch.
Both types involve handing control over to the operating system kernel to perform the context switch. The process of switching in and out of the OS kernel along with the cost of switching out the registers is the largest fixed cost of performing a context switch.



A more fuzzy cost is that a context switch messes with the processors cacheing mechanisms. Basically, when you context switch, all of the memory addresses that the processor "remembers" in it's cache effectively become useless. The one big distinction here is that when you change virtual memory spaces, the processor's Translation Lookaside Buffer (TLB) or equivalent gets flushed making memory accesses much more expensive for a while. This does not happen during a thread switch.






share|improve this answer





















  • 22





    Nice answer. I wish I knew this stuff that well!

    – CtrlDot
    Mar 26 '11 at 3:20






  • 6





    This is all assuming that the TLB and the cache don't store the pid for each entry.

    – dramzy
    Mar 20 '16 at 0:24






  • 1





    IMHO @dramzy is right, the OS may support Rapid Context Switching which is shortly mentioned here: youtu.be/3akTtCu_F_k?t=46m8s (watch from the beginning to know more about Virtual Memory, page tables and TLB).

    – piotrwest
    Jun 24 '16 at 23:05











  • @piotrwest Do any of the mainstream OS support Rapid Context Switching?

    – max
    May 6 '17 at 5:39






  • 2





    @dramzy Did you mean OS or the hardware could store the pid? Is this relevant?

    – max
    May 6 '17 at 5:44



















9














Process context switching involves switching the memory address space. This includes memory addresses, mappings, page tables, and kernel resources—a relatively expensive operation. On some architectures, it even means flushing various processor caches that aren't sharable across address spaces. For example, x86 has to flush the TLB and some ARM processors have to flush the entirety of the L1 cache!



Thread switching is context switching from one thread to another in the same process (switching from thread to thread across processes is just process switching).Switching processor state (such as the program counter and register contents) is generally very efficient.






share|improve this answer































    8














    First of all, operating system brings outgoing thread in a kernel mode if it is not already there, because thread switch can be performed only between threads, that runs in kernel mode. Then the scheduler is invoked to make a decision about thread to which will be performed switching. After decision is made, kernel saves part of the thread context that is located in CPU (CPU registers) into the dedicated place in memory (frequently on the top of the kernel stack of outgoing thread). Then the kernel performs switch from kernel stack of outgoing thread on to kernel stack of the incoming thread. After that, kernel loads previously stored context of incoming thread from memory into CPU registers. And finally returns control back into user mode, but in user mode of the new thread.
    In the case when OS has determined that incoming thread runs in another process, kernel performs one additional step: sets new active virtual address space.



    The main cost in both scenarios is related to a cache pollution. In most cases, the working set used by the outgoing thread will differ significantly from working set which is used by the incoming thread. As a result, the incoming thread will start its life with avalanche of cache misses, thus flushing old and useless data from the caches and loading the new data from memory. The same is true for TLB (Translation Look Aside Buffer, which is on the CPU). In the case of reset of virtual address space (threads run in different processes) the penalty is even worse, because reset of virtual address space leads to the flushing of the entire TLB, even if new thread actually needs to load only few new entries. As a result, the new thread will start its time quantum with lots TLB misses and frequent page walking. Direct cost of threads switch is also not negligible (from ~250 and up to ~1500-2000 cycles) and depends on the CPU complexity, states of both threads and sets of registers which they actually use.



    P.S.: Good post about context switch overhead: http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html






    share|improve this answer

































      3
















      • process switching: it is a transition between two memory resident of process in a multiprogramming environment;


      • context switching: it is a changing context from an executing program to an interrupt service routine (ISR).






      share|improve this answer

































        2














        In Thread Context Switching, the virtual memory space remains the same while it is not in the case of Process Context Switch. Also, Process Context Switch is costlier than Thread Context Switch.






        share|improve this answer































          0














          I think main difference is when calling switch_mm() which handles memory descriptors of old and new task. In the case of threads, the virtual memory address space is unchanged (threads share virtual memory), so very little has to be done, and therefore less costly.






          share|improve this answer































            -1














            In short, the thread context switch does not assign a brand new set of memory and pid, it uses the same as the parent since it is running within the same process. A process one spawns a new process and thus assigns new mem and pid.



            There is a loooooot more to it. They have written books on it.



            As for cost, a process context switch >>>> thread as you have to reset all of the stack counters etc.






            share|improve this answer































              -1














              Assuming that The CPU the OS runs has got Some High Latency Devices Attached,



              It makes sense to run another thread Of the Process's Address Space, while the high latency device responds back.



              But, if the High Latency Device is responding faster than the time to need do set up of table + translation of Virtual To Physical memories for a NEW Process, then it is questionable if a switch is essential at all.



              Also, HOT cache(data needed for running the process/thread is reachable in less time) is better choice.






              share|improve this answer

























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5440128%2fthread-context-switch-vs-process-context-switch%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                8 Answers
                8






                active

                oldest

                votes








                8 Answers
                8






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                163














                The main distinction between a thread switch and a process switch is that during a thread switch, the virtual memory space remains the same, while it does not during a process switch.
                Both types involve handing control over to the operating system kernel to perform the context switch. The process of switching in and out of the OS kernel along with the cost of switching out the registers is the largest fixed cost of performing a context switch.



                A more fuzzy cost is that a context switch messes with the processors cacheing mechanisms. Basically, when you context switch, all of the memory addresses that the processor "remembers" in it's cache effectively become useless. The one big distinction here is that when you change virtual memory spaces, the processor's Translation Lookaside Buffer (TLB) or equivalent gets flushed making memory accesses much more expensive for a while. This does not happen during a thread switch.






                share|improve this answer





















                • 22





                  Nice answer. I wish I knew this stuff that well!

                  – CtrlDot
                  Mar 26 '11 at 3:20






                • 6





                  This is all assuming that the TLB and the cache don't store the pid for each entry.

                  – dramzy
                  Mar 20 '16 at 0:24






                • 1





                  IMHO @dramzy is right, the OS may support Rapid Context Switching which is shortly mentioned here: youtu.be/3akTtCu_F_k?t=46m8s (watch from the beginning to know more about Virtual Memory, page tables and TLB).

                  – piotrwest
                  Jun 24 '16 at 23:05











                • @piotrwest Do any of the mainstream OS support Rapid Context Switching?

                  – max
                  May 6 '17 at 5:39






                • 2





                  @dramzy Did you mean OS or the hardware could store the pid? Is this relevant?

                  – max
                  May 6 '17 at 5:44
















                163














                The main distinction between a thread switch and a process switch is that during a thread switch, the virtual memory space remains the same, while it does not during a process switch.
                Both types involve handing control over to the operating system kernel to perform the context switch. The process of switching in and out of the OS kernel along with the cost of switching out the registers is the largest fixed cost of performing a context switch.



                A more fuzzy cost is that a context switch messes with the processors cacheing mechanisms. Basically, when you context switch, all of the memory addresses that the processor "remembers" in it's cache effectively become useless. The one big distinction here is that when you change virtual memory spaces, the processor's Translation Lookaside Buffer (TLB) or equivalent gets flushed making memory accesses much more expensive for a while. This does not happen during a thread switch.






                share|improve this answer





















                • 22





                  Nice answer. I wish I knew this stuff that well!

                  – CtrlDot
                  Mar 26 '11 at 3:20






                • 6





                  This is all assuming that the TLB and the cache don't store the pid for each entry.

                  – dramzy
                  Mar 20 '16 at 0:24






                • 1





                  IMHO @dramzy is right, the OS may support Rapid Context Switching which is shortly mentioned here: youtu.be/3akTtCu_F_k?t=46m8s (watch from the beginning to know more about Virtual Memory, page tables and TLB).

                  – piotrwest
                  Jun 24 '16 at 23:05











                • @piotrwest Do any of the mainstream OS support Rapid Context Switching?

                  – max
                  May 6 '17 at 5:39






                • 2





                  @dramzy Did you mean OS or the hardware could store the pid? Is this relevant?

                  – max
                  May 6 '17 at 5:44














                163












                163








                163







                The main distinction between a thread switch and a process switch is that during a thread switch, the virtual memory space remains the same, while it does not during a process switch.
                Both types involve handing control over to the operating system kernel to perform the context switch. The process of switching in and out of the OS kernel along with the cost of switching out the registers is the largest fixed cost of performing a context switch.



                A more fuzzy cost is that a context switch messes with the processors cacheing mechanisms. Basically, when you context switch, all of the memory addresses that the processor "remembers" in it's cache effectively become useless. The one big distinction here is that when you change virtual memory spaces, the processor's Translation Lookaside Buffer (TLB) or equivalent gets flushed making memory accesses much more expensive for a while. This does not happen during a thread switch.






                share|improve this answer















                The main distinction between a thread switch and a process switch is that during a thread switch, the virtual memory space remains the same, while it does not during a process switch.
                Both types involve handing control over to the operating system kernel to perform the context switch. The process of switching in and out of the OS kernel along with the cost of switching out the registers is the largest fixed cost of performing a context switch.



                A more fuzzy cost is that a context switch messes with the processors cacheing mechanisms. Basically, when you context switch, all of the memory addresses that the processor "remembers" in it's cache effectively become useless. The one big distinction here is that when you change virtual memory spaces, the processor's Translation Lookaside Buffer (TLB) or equivalent gets flushed making memory accesses much more expensive for a while. This does not happen during a thread switch.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 12 '13 at 20:46









                James Lim

                10.6k33057




                10.6k33057










                answered Mar 26 '11 at 3:18









                Abhay BuchAbhay Buch

                3,41711324




                3,41711324








                • 22





                  Nice answer. I wish I knew this stuff that well!

                  – CtrlDot
                  Mar 26 '11 at 3:20






                • 6





                  This is all assuming that the TLB and the cache don't store the pid for each entry.

                  – dramzy
                  Mar 20 '16 at 0:24






                • 1





                  IMHO @dramzy is right, the OS may support Rapid Context Switching which is shortly mentioned here: youtu.be/3akTtCu_F_k?t=46m8s (watch from the beginning to know more about Virtual Memory, page tables and TLB).

                  – piotrwest
                  Jun 24 '16 at 23:05











                • @piotrwest Do any of the mainstream OS support Rapid Context Switching?

                  – max
                  May 6 '17 at 5:39






                • 2





                  @dramzy Did you mean OS or the hardware could store the pid? Is this relevant?

                  – max
                  May 6 '17 at 5:44














                • 22





                  Nice answer. I wish I knew this stuff that well!

                  – CtrlDot
                  Mar 26 '11 at 3:20






                • 6





                  This is all assuming that the TLB and the cache don't store the pid for each entry.

                  – dramzy
                  Mar 20 '16 at 0:24






                • 1





                  IMHO @dramzy is right, the OS may support Rapid Context Switching which is shortly mentioned here: youtu.be/3akTtCu_F_k?t=46m8s (watch from the beginning to know more about Virtual Memory, page tables and TLB).

                  – piotrwest
                  Jun 24 '16 at 23:05











                • @piotrwest Do any of the mainstream OS support Rapid Context Switching?

                  – max
                  May 6 '17 at 5:39






                • 2





                  @dramzy Did you mean OS or the hardware could store the pid? Is this relevant?

                  – max
                  May 6 '17 at 5:44








                22




                22





                Nice answer. I wish I knew this stuff that well!

                – CtrlDot
                Mar 26 '11 at 3:20





                Nice answer. I wish I knew this stuff that well!

                – CtrlDot
                Mar 26 '11 at 3:20




                6




                6





                This is all assuming that the TLB and the cache don't store the pid for each entry.

                – dramzy
                Mar 20 '16 at 0:24





                This is all assuming that the TLB and the cache don't store the pid for each entry.

                – dramzy
                Mar 20 '16 at 0:24




                1




                1





                IMHO @dramzy is right, the OS may support Rapid Context Switching which is shortly mentioned here: youtu.be/3akTtCu_F_k?t=46m8s (watch from the beginning to know more about Virtual Memory, page tables and TLB).

                – piotrwest
                Jun 24 '16 at 23:05





                IMHO @dramzy is right, the OS may support Rapid Context Switching which is shortly mentioned here: youtu.be/3akTtCu_F_k?t=46m8s (watch from the beginning to know more about Virtual Memory, page tables and TLB).

                – piotrwest
                Jun 24 '16 at 23:05













                @piotrwest Do any of the mainstream OS support Rapid Context Switching?

                – max
                May 6 '17 at 5:39





                @piotrwest Do any of the mainstream OS support Rapid Context Switching?

                – max
                May 6 '17 at 5:39




                2




                2





                @dramzy Did you mean OS or the hardware could store the pid? Is this relevant?

                – max
                May 6 '17 at 5:44





                @dramzy Did you mean OS or the hardware could store the pid? Is this relevant?

                – max
                May 6 '17 at 5:44













                9














                Process context switching involves switching the memory address space. This includes memory addresses, mappings, page tables, and kernel resources—a relatively expensive operation. On some architectures, it even means flushing various processor caches that aren't sharable across address spaces. For example, x86 has to flush the TLB and some ARM processors have to flush the entirety of the L1 cache!



                Thread switching is context switching from one thread to another in the same process (switching from thread to thread across processes is just process switching).Switching processor state (such as the program counter and register contents) is generally very efficient.






                share|improve this answer




























                  9














                  Process context switching involves switching the memory address space. This includes memory addresses, mappings, page tables, and kernel resources—a relatively expensive operation. On some architectures, it even means flushing various processor caches that aren't sharable across address spaces. For example, x86 has to flush the TLB and some ARM processors have to flush the entirety of the L1 cache!



                  Thread switching is context switching from one thread to another in the same process (switching from thread to thread across processes is just process switching).Switching processor state (such as the program counter and register contents) is generally very efficient.






                  share|improve this answer


























                    9












                    9








                    9







                    Process context switching involves switching the memory address space. This includes memory addresses, mappings, page tables, and kernel resources—a relatively expensive operation. On some architectures, it even means flushing various processor caches that aren't sharable across address spaces. For example, x86 has to flush the TLB and some ARM processors have to flush the entirety of the L1 cache!



                    Thread switching is context switching from one thread to another in the same process (switching from thread to thread across processes is just process switching).Switching processor state (such as the program counter and register contents) is generally very efficient.






                    share|improve this answer













                    Process context switching involves switching the memory address space. This includes memory addresses, mappings, page tables, and kernel resources—a relatively expensive operation. On some architectures, it even means flushing various processor caches that aren't sharable across address spaces. For example, x86 has to flush the TLB and some ARM processors have to flush the entirety of the L1 cache!



                    Thread switching is context switching from one thread to another in the same process (switching from thread to thread across processes is just process switching).Switching processor state (such as the program counter and register contents) is generally very efficient.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 24 '14 at 3:57









                    aditya dograaditya dogra

                    14921




                    14921























                        8














                        First of all, operating system brings outgoing thread in a kernel mode if it is not already there, because thread switch can be performed only between threads, that runs in kernel mode. Then the scheduler is invoked to make a decision about thread to which will be performed switching. After decision is made, kernel saves part of the thread context that is located in CPU (CPU registers) into the dedicated place in memory (frequently on the top of the kernel stack of outgoing thread). Then the kernel performs switch from kernel stack of outgoing thread on to kernel stack of the incoming thread. After that, kernel loads previously stored context of incoming thread from memory into CPU registers. And finally returns control back into user mode, but in user mode of the new thread.
                        In the case when OS has determined that incoming thread runs in another process, kernel performs one additional step: sets new active virtual address space.



                        The main cost in both scenarios is related to a cache pollution. In most cases, the working set used by the outgoing thread will differ significantly from working set which is used by the incoming thread. As a result, the incoming thread will start its life with avalanche of cache misses, thus flushing old and useless data from the caches and loading the new data from memory. The same is true for TLB (Translation Look Aside Buffer, which is on the CPU). In the case of reset of virtual address space (threads run in different processes) the penalty is even worse, because reset of virtual address space leads to the flushing of the entire TLB, even if new thread actually needs to load only few new entries. As a result, the new thread will start its time quantum with lots TLB misses and frequent page walking. Direct cost of threads switch is also not negligible (from ~250 and up to ~1500-2000 cycles) and depends on the CPU complexity, states of both threads and sets of registers which they actually use.



                        P.S.: Good post about context switch overhead: http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html






                        share|improve this answer






























                          8














                          First of all, operating system brings outgoing thread in a kernel mode if it is not already there, because thread switch can be performed only between threads, that runs in kernel mode. Then the scheduler is invoked to make a decision about thread to which will be performed switching. After decision is made, kernel saves part of the thread context that is located in CPU (CPU registers) into the dedicated place in memory (frequently on the top of the kernel stack of outgoing thread). Then the kernel performs switch from kernel stack of outgoing thread on to kernel stack of the incoming thread. After that, kernel loads previously stored context of incoming thread from memory into CPU registers. And finally returns control back into user mode, but in user mode of the new thread.
                          In the case when OS has determined that incoming thread runs in another process, kernel performs one additional step: sets new active virtual address space.



                          The main cost in both scenarios is related to a cache pollution. In most cases, the working set used by the outgoing thread will differ significantly from working set which is used by the incoming thread. As a result, the incoming thread will start its life with avalanche of cache misses, thus flushing old and useless data from the caches and loading the new data from memory. The same is true for TLB (Translation Look Aside Buffer, which is on the CPU). In the case of reset of virtual address space (threads run in different processes) the penalty is even worse, because reset of virtual address space leads to the flushing of the entire TLB, even if new thread actually needs to load only few new entries. As a result, the new thread will start its time quantum with lots TLB misses and frequent page walking. Direct cost of threads switch is also not negligible (from ~250 and up to ~1500-2000 cycles) and depends on the CPU complexity, states of both threads and sets of registers which they actually use.



                          P.S.: Good post about context switch overhead: http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html






                          share|improve this answer




























                            8












                            8








                            8







                            First of all, operating system brings outgoing thread in a kernel mode if it is not already there, because thread switch can be performed only between threads, that runs in kernel mode. Then the scheduler is invoked to make a decision about thread to which will be performed switching. After decision is made, kernel saves part of the thread context that is located in CPU (CPU registers) into the dedicated place in memory (frequently on the top of the kernel stack of outgoing thread). Then the kernel performs switch from kernel stack of outgoing thread on to kernel stack of the incoming thread. After that, kernel loads previously stored context of incoming thread from memory into CPU registers. And finally returns control back into user mode, but in user mode of the new thread.
                            In the case when OS has determined that incoming thread runs in another process, kernel performs one additional step: sets new active virtual address space.



                            The main cost in both scenarios is related to a cache pollution. In most cases, the working set used by the outgoing thread will differ significantly from working set which is used by the incoming thread. As a result, the incoming thread will start its life with avalanche of cache misses, thus flushing old and useless data from the caches and loading the new data from memory. The same is true for TLB (Translation Look Aside Buffer, which is on the CPU). In the case of reset of virtual address space (threads run in different processes) the penalty is even worse, because reset of virtual address space leads to the flushing of the entire TLB, even if new thread actually needs to load only few new entries. As a result, the new thread will start its time quantum with lots TLB misses and frequent page walking. Direct cost of threads switch is also not negligible (from ~250 and up to ~1500-2000 cycles) and depends on the CPU complexity, states of both threads and sets of registers which they actually use.



                            P.S.: Good post about context switch overhead: http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html






                            share|improve this answer















                            First of all, operating system brings outgoing thread in a kernel mode if it is not already there, because thread switch can be performed only between threads, that runs in kernel mode. Then the scheduler is invoked to make a decision about thread to which will be performed switching. After decision is made, kernel saves part of the thread context that is located in CPU (CPU registers) into the dedicated place in memory (frequently on the top of the kernel stack of outgoing thread). Then the kernel performs switch from kernel stack of outgoing thread on to kernel stack of the incoming thread. After that, kernel loads previously stored context of incoming thread from memory into CPU registers. And finally returns control back into user mode, but in user mode of the new thread.
                            In the case when OS has determined that incoming thread runs in another process, kernel performs one additional step: sets new active virtual address space.



                            The main cost in both scenarios is related to a cache pollution. In most cases, the working set used by the outgoing thread will differ significantly from working set which is used by the incoming thread. As a result, the incoming thread will start its life with avalanche of cache misses, thus flushing old and useless data from the caches and loading the new data from memory. The same is true for TLB (Translation Look Aside Buffer, which is on the CPU). In the case of reset of virtual address space (threads run in different processes) the penalty is even worse, because reset of virtual address space leads to the flushing of the entire TLB, even if new thread actually needs to load only few new entries. As a result, the new thread will start its time quantum with lots TLB misses and frequent page walking. Direct cost of threads switch is also not negligible (from ~250 and up to ~1500-2000 cycles) and depends on the CPU complexity, states of both threads and sets of registers which they actually use.



                            P.S.: Good post about context switch overhead: http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 25 '18 at 14:48









                            Guy Avraham

                            1,48222031




                            1,48222031










                            answered Oct 27 '16 at 10:16









                            ZarathustrAZarathustrA

                            2,0062018




                            2,0062018























                                3
















                                • process switching: it is a transition between two memory resident of process in a multiprogramming environment;


                                • context switching: it is a changing context from an executing program to an interrupt service routine (ISR).






                                share|improve this answer






























                                  3
















                                  • process switching: it is a transition between two memory resident of process in a multiprogramming environment;


                                  • context switching: it is a changing context from an executing program to an interrupt service routine (ISR).






                                  share|improve this answer




























                                    3












                                    3








                                    3









                                    • process switching: it is a transition between two memory resident of process in a multiprogramming environment;


                                    • context switching: it is a changing context from an executing program to an interrupt service routine (ISR).






                                    share|improve this answer

















                                    • process switching: it is a transition between two memory resident of process in a multiprogramming environment;


                                    • context switching: it is a changing context from an executing program to an interrupt service routine (ISR).







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Dec 3 '12 at 5:52









                                    tiago

                                    12.7k85475




                                    12.7k85475










                                    answered Dec 3 '12 at 5:32









                                    johnjohn

                                    391




                                    391























                                        2














                                        In Thread Context Switching, the virtual memory space remains the same while it is not in the case of Process Context Switch. Also, Process Context Switch is costlier than Thread Context Switch.






                                        share|improve this answer




























                                          2














                                          In Thread Context Switching, the virtual memory space remains the same while it is not in the case of Process Context Switch. Also, Process Context Switch is costlier than Thread Context Switch.






                                          share|improve this answer


























                                            2












                                            2








                                            2







                                            In Thread Context Switching, the virtual memory space remains the same while it is not in the case of Process Context Switch. Also, Process Context Switch is costlier than Thread Context Switch.






                                            share|improve this answer













                                            In Thread Context Switching, the virtual memory space remains the same while it is not in the case of Process Context Switch. Also, Process Context Switch is costlier than Thread Context Switch.







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Feb 14 '18 at 12:40









                                            Palak JainPalak Jain

                                            39529




                                            39529























                                                0














                                                I think main difference is when calling switch_mm() which handles memory descriptors of old and new task. In the case of threads, the virtual memory address space is unchanged (threads share virtual memory), so very little has to be done, and therefore less costly.






                                                share|improve this answer




























                                                  0














                                                  I think main difference is when calling switch_mm() which handles memory descriptors of old and new task. In the case of threads, the virtual memory address space is unchanged (threads share virtual memory), so very little has to be done, and therefore less costly.






                                                  share|improve this answer


























                                                    0












                                                    0








                                                    0







                                                    I think main difference is when calling switch_mm() which handles memory descriptors of old and new task. In the case of threads, the virtual memory address space is unchanged (threads share virtual memory), so very little has to be done, and therefore less costly.






                                                    share|improve this answer













                                                    I think main difference is when calling switch_mm() which handles memory descriptors of old and new task. In the case of threads, the virtual memory address space is unchanged (threads share virtual memory), so very little has to be done, and therefore less costly.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Oct 22 '18 at 14:17









                                                    Dražen G.Dražen G.

                                                    1015




                                                    1015























                                                        -1














                                                        In short, the thread context switch does not assign a brand new set of memory and pid, it uses the same as the parent since it is running within the same process. A process one spawns a new process and thus assigns new mem and pid.



                                                        There is a loooooot more to it. They have written books on it.



                                                        As for cost, a process context switch >>>> thread as you have to reset all of the stack counters etc.






                                                        share|improve this answer




























                                                          -1














                                                          In short, the thread context switch does not assign a brand new set of memory and pid, it uses the same as the parent since it is running within the same process. A process one spawns a new process and thus assigns new mem and pid.



                                                          There is a loooooot more to it. They have written books on it.



                                                          As for cost, a process context switch >>>> thread as you have to reset all of the stack counters etc.






                                                          share|improve this answer


























                                                            -1












                                                            -1








                                                            -1







                                                            In short, the thread context switch does not assign a brand new set of memory and pid, it uses the same as the parent since it is running within the same process. A process one spawns a new process and thus assigns new mem and pid.



                                                            There is a loooooot more to it. They have written books on it.



                                                            As for cost, a process context switch >>>> thread as you have to reset all of the stack counters etc.






                                                            share|improve this answer













                                                            In short, the thread context switch does not assign a brand new set of memory and pid, it uses the same as the parent since it is running within the same process. A process one spawns a new process and thus assigns new mem and pid.



                                                            There is a loooooot more to it. They have written books on it.



                                                            As for cost, a process context switch >>>> thread as you have to reset all of the stack counters etc.







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Mar 26 '11 at 3:14









                                                            CtrlDotCtrlDot

                                                            2,143910




                                                            2,143910























                                                                -1














                                                                Assuming that The CPU the OS runs has got Some High Latency Devices Attached,



                                                                It makes sense to run another thread Of the Process's Address Space, while the high latency device responds back.



                                                                But, if the High Latency Device is responding faster than the time to need do set up of table + translation of Virtual To Physical memories for a NEW Process, then it is questionable if a switch is essential at all.



                                                                Also, HOT cache(data needed for running the process/thread is reachable in less time) is better choice.






                                                                share|improve this answer






























                                                                  -1














                                                                  Assuming that The CPU the OS runs has got Some High Latency Devices Attached,



                                                                  It makes sense to run another thread Of the Process's Address Space, while the high latency device responds back.



                                                                  But, if the High Latency Device is responding faster than the time to need do set up of table + translation of Virtual To Physical memories for a NEW Process, then it is questionable if a switch is essential at all.



                                                                  Also, HOT cache(data needed for running the process/thread is reachable in less time) is better choice.






                                                                  share|improve this answer




























                                                                    -1












                                                                    -1








                                                                    -1







                                                                    Assuming that The CPU the OS runs has got Some High Latency Devices Attached,



                                                                    It makes sense to run another thread Of the Process's Address Space, while the high latency device responds back.



                                                                    But, if the High Latency Device is responding faster than the time to need do set up of table + translation of Virtual To Physical memories for a NEW Process, then it is questionable if a switch is essential at all.



                                                                    Also, HOT cache(data needed for running the process/thread is reachable in less time) is better choice.






                                                                    share|improve this answer















                                                                    Assuming that The CPU the OS runs has got Some High Latency Devices Attached,



                                                                    It makes sense to run another thread Of the Process's Address Space, while the high latency device responds back.



                                                                    But, if the High Latency Device is responding faster than the time to need do set up of table + translation of Virtual To Physical memories for a NEW Process, then it is questionable if a switch is essential at all.



                                                                    Also, HOT cache(data needed for running the process/thread is reachable in less time) is better choice.







                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Oct 17 '15 at 5:02

























                                                                    answered Dec 29 '11 at 1:52









                                                                    delete medelete me

                                                                    6010




                                                                    6010






























                                                                        draft saved

                                                                        draft discarded




















































                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid



                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function () {
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5440128%2fthread-context-switch-vs-process-context-switch%23new-answer', 'question_page');
                                                                        }
                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        Popular posts from this blog

                                                                        A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                                                                        Calculate evaluation metrics using cross_val_predict sklearn

                                                                        Insert data from modal to MySQL (multiple modal on website)