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

Reply to
Tony
Loading thread data ...

I'm not sure what those mean.

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

...

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

Reply to
Alexei A. Frounze

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.

It depends on which JVM you use.

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.

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
Kasper Dupont

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.