User threads versus kernel threads
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: User threads versus kernel threads

Hybrid View

  1. #1
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    User threads versus kernel threads

    Okay, multithreading 101: threading can be done either in user mode or kernel mode, or some combination thereof. The advantage of user mode threading is that you don't have expensive kernel-mode function calls to worry about. The advantage of kernel mode threading is that a blocking kernel call can be made to block only one thread rather than the entire process.

    What I'm not entirely clear on is to what degree each of the various threading packages uses each paradigm, and what optimization options are available when, for instance, you know that user-mode synchronization is good enough and you don't want to pay for a kernel call.

    Anyone have any insight in this regard?
    Share on Google+

  2. #2
    Join Date
    Apr 2010
    Posts
    27

    Re: User threads versus kernel threads

    First of all, user mode "threads" (fibers) are not actually threads in the sense that they do not allow one to utilize parallel hardware. They are useful only as a replacement for explicit state machines and continuations. They are no more than "a syntactic sugar" in the context of parallel hardware.

    Then, kernel mode threads do use user-level synchronization w/o kernel calls. pthread_mutex_t, CRITICAL_SECTION are all fast-pathed in user space, not saying about __sync_XXX/_InterlocedXXX functions. Kernel threads do not imply kernel synchronization.

    Moreover, provided cooperative user mode scheduling blocked fiber does not have to block the entire underlying thread. Take a look at a Windows 7 UMS (user mode scheduling).

    As a bottom line. If you need to utilize parallel hardware you must use kernel threads. User threads is a mean for program structuring and have nothing to do with concurrency.

    There is also quite popular nowadays abstraction of tasks, which are basically lightweight user threads. Modern libraries usually use kernel threads for concurrency, and tasks (which run on top of kernel threads) for program structuring.
    Share on Google+

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: User threads versus kernel threads

    That makes sense, thanks. Tasks I presume being related to the thread pool pattern.
    Share on Google+

  4. #4
    Join Date
    Apr 2010
    Posts
    27

    Re: User threads versus kernel threads

    > Tasks I presume being related to the thread pool pattern.

    Yes, a pool of kernel threads execute a set of tasks.
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center