-3

In continuation to question, This is an additional query on N-1 threading model.

enter image description here

It is taught that, before designing an application, selection of threading model need to be taken care.

In N-1 threading model, a single kernel thread is available to work on behalf of each user process. OS scheduler gives a single CPU time slice to this kernel thread.

In user space, programmer would use either POSIX pthread or Windows CreateThread() to spawn multiple threads within a user process. As the programmer used POSIX pthread or Windows CreateThread() the kernel is aware of the user-land threads and each thread is considered for processor time assignment by the scheduler. SO, that means every user thread will get a kernel thread.

My question:

So, How does N-1 threading model looks possible to exist? It would be 1-1 threading model. Please clarify.

8
  • Please add a comment for the reason to down vote, so that i can correct my mistake. Oct 13, 2014 at 1:52
  • I didn't downvote but you should probably put in what you have tried and make your question clearer/concise and free-standing. You should probably also narrow the scope down to something answerable. As it stands, it strikes me as a homework question.
    – tangrs
    Oct 13, 2014 at 3:50
  • @tangrs This is self-development learning but not a homework question. The word taught that refers to an online lecture that address this point. It is too far to think of designing any concurrent/network application without having clarity on threading models. Oct 13, 2014 at 3:55
  • Using platform specific threading facilities is discouraged in favor of C11's threading facilities. Oct 13, 2014 at 8:16
  • @nif Can you please comment on this query? Oct 13, 2014 at 8:42

2 Answers 2

1

In user space, programmer would use either POSIX pthread or Windows CreateThread() to spawn multiple threads within a user process. As the programmer used POSIX pthread or Windows CreateThread() the kernel is aware of the user-land threads and each thread is considered for processor time assignment by the scheduler. SO, that means every user thread will get a kernel thread.

That's how 1-to-1 threading works.

This doesn't have to be the case. A platform can implement pthread_create, CreateThread, or whatever other "create a thread" function it offers that does whatever it wants.

My question:

So, How does N-1 threading model looks possible to exist? It would be 1-1 threading model.
Please clarify.

Precisely as you explained in the beginning of your question -- when the programmer creates a thread, instead of creating a thread the kernel is aware of, it creates a thread that the userland scheduler is aware of, still using a single kernel thread for the entire process.

4
  • So, Java programmer do not have control over working in 1-1 or Hybrid model environment. He has only choice to work in N-1 threading model environment, Because, JVM is taking care of creating and scheduling threads instead of kernel. am i correct? Oct 14, 2014 at 8:22
  • 1
    @overexchange No. A Java programmer can write a Java program that implements hybrid threading or N-to-1 threading if they want. The JVM typically provides 1-to-1 threads, which the programmer can use or not use at their option. Oct 14, 2014 at 23:32
  • Ok, So, If Java code inherits and use Java.lang.Thread class from Oracle, then JVM internally provides 1-1 threading model for you.am i correct? Oct 15, 2014 at 7:35
  • 1
    @overexchange Today, yes. Green threads were common in the early days of Java. Oct 15, 2014 at 16:42
1

Short answer: there is more than Windows and Linux.

Slightly longer answer (EDITED):

Many programming languages and frameworks introduce multithreading to the programmer. At the same time, they aim to be portable, i.e., it is not known, whether any target plattform does support threads at all. Here, the best way is to implement a N:1 threading, either in general, are at least for the backends without threading support.

The classic example is Java: the language supports multithreading, while JVMs exist even for very simple embedded plattforms, that do not support threads. However, there are JVMs (actually, most of them) that use kernel threads (e.g. AFIK, the JVM by Sun/Oracle).

Another reason that a language/plattform does not want to transfer the threading control completely to the operating system are sometimes special implementation features as reactor modells or global language locks. Here, the objective is to use information on execution special patterns in the user runtime system (which does the local scheduling) that the OS scheduling has no access to.

 Does [1:1 threading] add more space occupancy on User process virtual 
 address space because of these kernel threads?

Well, in theory, execution flow (processes, threads, etc.) and address space are independent concepts. One can find all kinds of mapping between processes (here used as a general term) and memory spaces: 1:1, n:1, 1:n, n:n. However, the classic approach of threading is that several threads of a process share the memory space of the task (that is the owner of the memory space). And thus, there is usually no difference between user threads and kernel threads regarding the memory space. (One exception is, e.g., the Erlang-VM: here, there exist user threads with isolated memory spaces).

3
  • 1) So, user Process(running java code) that run under JVM(excluding embedded platforms) look exactly like N-1 threading model, where thread implementation/scheduling is known to jvm process but not to kernel. am i correct? 2) In contrast, If user process(using pthread_create() or windows CreateThread()) actually intimates kernel to associate a kernel thread for each user thread, which leads to 1-1 threading model. am i correct? Oct 13, 2014 at 15:36
  • I did not get this point are sometimes special implementation features as reactor modells or global language locks Oct 13, 2014 at 15:41
  • As 1-1 threading model has kernel thread for each user land thread, Does this add more space occupancy on User process virtual address space because of these kernel threads? Oct 13, 2014 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.