Multithreading model: can it be selected? - Embedded

This is a discussion on Multithreading model: can it be selected? - Embedded ; Hi, I have read about the user level / kernel level threading as well as the three threading model : Many to One, One to One, Many to Many. I noticed that any OS tends to support more than one ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Multithreading model: can it be selected?

  1. Multithreading model: can it be selected?



    Hi,

    I have read about the user level / kernel level threading as well as
    the three threading model : Many to One, One to One, Many to Many.

    I noticed that any OS tends to support more than one threading model.
    Windows NT seems to support Many to Many and One to one. If the user
    writes a multithreading application does he have the freedom to select
    which threading model he wants to use?
    I have in mind particularly Java and Pthreads. For instance while
    writing a java multithreaded application, I can't find an instruction
    to select a particular threading model. Does JVM have a default
    setting? I have read that it used to be Many to one in old version and
    current version is for instance 1:1 in windows NT although that the
    latest supports also Many to Many
    What about other packages (Pthread)?


    Another questions some references tend to claim that while using user
    level thread library, the scheduling can't be pre-emptive. I think
    this possible if a timer is used. Why such solution has not been
    adopted


    Thanks


  2. Re: Multithreading model: can it be selected?

    "Tony" wrote in message
    news:1141946190.152835.264840@e56g2000cwe.googlegr oups.com...
    > I have read about the user level / kernel level threading as well as
    > the three threading model : Many to One, One to One, Many to Many.


    I'm not sure what those mean.

    > I noticed that any OS tends to support more than one threading model.
    > Windows NT seems to support Many to Many and One to one. If the user
    > writes a multithreading application does he have the freedom to select
    > which threading model he wants to use?


    Usually, no. QNX though provides some nice scheduling policies/algorithms,
    which can be selected on a per thread basis.

    ....
    > Another questions some references tend to claim that while using user
    > level thread library, the scheduling can't be pre-emptive. I think
    > this possible if a timer is used. Why such solution has not been
    > adopted


    I don't know. In part maybe because that is already provided by the kernel
    in the threading models which you don't enjoy and want your own...

    Alex



  3. Re: Multithreading model: can it be selected?

    Tony wrote:
    >
    > Hi,
    >
    > I have read about the user level / kernel level threading as well as
    > the three threading model : Many to One, One to One, Many to Many.


    It all depends on the threading library. However on Linux there is
    no point in letting the application select since one to one works
    just fine. The other models were invented for kernels that would
    otherwise have performance problems.

    I can only think of one case where you might be able to save a few
    context switches by using many to many rather than one to one.
    However it would be so complicated involving lots of coordination
    between the kernel scheduler and the user mode scheduler, that I
    doubt it is worth the effort.

    >
    > I noticed that any OS tends to support more than one threading model.
    > Windows NT seems to support Many to Many and One to one. If the user
    > writes a multithreading application does he have the freedom to select
    > which threading model he wants to use?
    > I have in mind particularly Java and Pthreads. For instance while
    > writing a java multithreaded application, I can't find an instruction
    > to select a particular threading model. Does JVM have a default
    > setting? I have read that it used to be Many to one in old version and
    > current version is for instance 1:1 in windows NT although that the
    > latest supports also Many to Many


    It depends on which JVM you use.

    > What about other packages (Pthread)?


    There is an old threading library, which was typically used on
    2.4 and earlier. There is a new one used on 2.6. A 2.6 kernel with
    the new threading library give better performance and better
    standards compliance. They both use one to one by default, and I
    don't think they support anything else.

    >
    > Another questions some references tend to claim that while using user
    > level thread library, the scheduling can't be pre-emptive. I think
    > this possible if a timer is used. Why such solution has not been
    > adopted


    Yes, it can be done. However a timer means you need a timer
    interrupt and do the switching in a signal handler. That means
    you have to enter the kernel twice to switch thread, once to
    enter the signal handler, and once to leave the signal handler.
    If threading is implemented in kernel mode, you only need to
    enter the kernel once to switch. So there goes the performance
    advantage.

    Then there are all the complications you would get from doing
    it in user mode. When one thread performs a blocking system
    call, the kernel will give no more CPU time to the process. So
    you would not be able to use the CPU time for other threads. To
    work around this problem, the threading library would have to
    replace all blocking system calls with its own versions
    implemented using non-blocking calls, and then do the blocking
    on its own.

    --
    Kasper Dupont -- Rigtige mænd skriver deres egne backupprogrammer
    #define _(_)"d.%.4s%."_"2s" /* This is my new email address */
    char*_="@2kaspner"_()"%03"_("4s%.")"t\n";printf(_+11,_+6,_,6,_+2,_+7,_+6);

+ Reply to Thread