Thread: Switching between user-level and kernel-level threads

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    20

    Post Switching between user-level and kernel-level threads

    Hey Guys/Girls,
    I'm back to this site but to this new forum(Tech Board) .My Question is realated to Operating Systems and might be not out of place here.

    After reading difference between user-level threads and kernel-level threads ,now I am in doubt of context switching.Context switching is managed by OS when switching between processes/threads but google didn't clarify me when i asked it that in which case more number of switching will take place for these cases :

    1). User-level thread switched to another user-level
    2). Kernel-level thread switched to another kernel-level
    3). User-level thread switched to kernel-level
    Anyone having a know-how please make it clear
    Last edited by Salem; 12-16-2014 at 12:11 AM. Reason: font abuse

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I do not see the significance of the type of thread. When you switch between two thread, regardless of what types those are, you need to make a context switch.
    Also, please don't change the font.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    20
    "In which case more number of switching would take place"?? is my Question

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Not enough information, like I said! If you transition between two threads, there will always be a context switch.
    If you have KT and transition to a UT, you get a context switch.
    If you have UT and transition to a KT, you get a context switch.
    If you have KT and transition to a KT, you get a context switch.
    If you have UT and transition to a UT, you get a context switch.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    What Elysia said.

    Also, what do you mean by "more number of switching"? I understand English may not be your native language, but please try to explain more clearly

    Lastly, this is very OS-specific (and probably threading-library specific). You should probably tell us what OS you want info for.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    [Edit]For best results, replace most uses of "system" with "environment".[/Edit]

    O_o

    1): You are potentially talking about the exact same thing with different labels.

    Many systems do not make any such distinction.

    2): You are potentially talking about almost the exact same thing with different labels.

    Many systems have no such division between "user-level" and "kernel-level" threads. On such systems, one thread model is provided which only may have privilege depending on the privilege on the owning process.

    3): You are potentially talking about the same mechanisms with different API use and requirements.

    Many systems have different ways of exposing threading, regardless of the name, which have different uses. However, different threading mechanisms also have different requirements. If, for example, you used one fairly uncommon threading mechanism which is particularly thin you are required to avoid the majority of API calls or risk a context switch in any event thus eliminating the benefit of using such an uncommon mechanism. If, another example, you use a common mechanism you'll see context switch for a variety of reasons because the mechanism is more general purpose. In either example case, you will see context switches which the scheduler decides a thread has received enough attention.

    4): You are potentially talking about threads provided by the kernel scheduler versus threads managed by a process such as a virtual machine.

    Many systems have only a single threading mechanism, but a system usually doesn't and can't prevent a process from creating a threading mechanism. Many languages, like Go for example, use a combination of tools to implement a threading mechanism that the kernel scheduler never knows about. Such threading mechanisms which are separated from the kernel scheduler do not actually have context switches. The cost of changing such threads is effectively the same as calling a different function, but the cost of calling a mechanism that blocks is similarly the same as calling a mechanism that blocks in an application which does not use thread.

    *shrug*

    On one hand, you could say that Elysia is definitely wrong about there always being a context switch. On the other hand, you could certainly say that Elysia is right about not having enough information. We don't even know what sort of threads you are talking about.

    Soma
    Last edited by phantomotap; 12-16-2014 at 12:19 AM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  7. #7
    Registered User
    Join Date
    Jul 2013
    Posts
    20
    Seeing the various comments here asking for type of OS or the information in itself is not complete,I would rather say the Question in a form similar to this was asked on an exam paper in Multiple Choice Question's .I was blunt to see it and so came here to seek guidance

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Javed Iqbal View Post
    Seeing the various comments here asking for type of OS or the information in itself is not complete,I would rather say the Question in a form similar to this was asked on an exam paper in Multiple Choice Question's .I was blunt to see it and so came here to seek guidance
    It will not surprise any of the seasoned developers in here the sorry state of computer programming education in schools, and even the vast majority of universities. So that quote isn't going to be met with a shocking expression. Our teaching institutions can't even come close to compete with a simple blog like Meyers' or a programming website like Dr. Dobbs.

    There are exceptions of course. But I find it funnier to tell of the stories that confirm the rule. For instance, of a certain university that chooses F# as their language for Introduction of Programming in their SEC. Not happy with just that, they then chose to install a localized version of the programming language. Portuguese to be more exact. Microsoft, in all its wisdom, offers localized versions of some programming languages, with all keywords translated to the localized language. And someone other than the Microsoft monkeys that came up with it, thinks this is not only a great idea, but also something that should be used to teach programming in an university.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    Registered User
    Join Date
    Jul 2013
    Posts
    20
    Quote Originally Posted by Mario F. View Post
    It will not surprise any of the seasoned developers in here the sorry state of computer programming education in schools, and even the vast majority of universities. So that quote isn't going to be met with a shocking expression. Our teaching institutions can't even come close to compete with a simple blog like Meyers' or a programming website like Dr. Dobbs.

    There are exceptions of course. But I find it funnier to tell of the stories that confirm the rule. For instance, of a certain university that chooses F# as their language for Introduction of Programming in their SEC. Not happy with just that, they then chose to install a localized version of the programming language. Portuguese to be more exact. Microsoft, in all its wisdom, offers localized versions of some programming languages, with all keywords translated to the localized language. And someone other than the Microsoft monkeys that came up with it, thinks this is not only a great idea, but also something that should be used to teach programming in an university.





    LOL.

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    And someone other than the Microsoft monkeys that came up with it, thinks this is not only a great idea, but also something that should be used to teach programming in an university.
    O_o

    I've seen a lot of dumb things come out of education, but that may yet take the cake.

    That is atrocious.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function-level variables and threads
    By m37h0d in forum C++ Programming
    Replies: 8
    Last Post: 01-18-2012, 08:47 PM
  2. Low Level I/O
    By DickArmy in forum C Programming
    Replies: 2
    Last Post: 10-31-2009, 01:26 PM
  3. replace a file in user level
    By munna_dude in forum Linux Programming
    Replies: 5
    Last Post: 09-01-2007, 02:16 PM
  4. C++ to the next level
    By Daggie in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2003, 07:43 AM
  5. Low-Level and High-level ::: C-style And C++ Style
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-22-2001, 05:05 PM