-2

I know that there is multithreading vs multiprocessing approach.
But I was under the impression that threads are implemented as processes by the OS. So the threading model is just a programming construct on top of processes.
At least in Java (hence the tag although this question is language agnostic) I know that the threads are implemented by the linux as processes Is it not the general case? Does it depend on the OS?

UPDATE for Java asked in comment by @SotiriosDelimanolis: One to one mapping of Java Thread to Linux thread (LWP)

Community
  • 1
  • 1
Jim
  • 18,826
  • 34
  • 135
  • 254
  • 3
    _I know that the threads are implemented by the linux as processes._ How do you know this? – Sotirios Delimanolis Nov 10 '14 at 19:09
  • @SotiriosDelimanolis:I have read it in the past that they are implemented as lwp processes.I can look up a reference if you want – Jim Nov 10 '14 at 19:12
  • 1
    In Windows, threads are not implemented as processes. – Harry Johnston Nov 10 '14 at 19:45
  • @HarryJohnston:Then how? – Jim Nov 11 '14 at 19:11
  • 1
    In Windows, processes are higher-level constructs that encompass the runtime environment: code, data memory-management, working-set, security permissions etc. The basic unit of execution is a thread, which requires a stack. All processes require at least one thread, and the OS loader creates it at process startup to run the code at the executable entry point. That thread is free to create more threads that become a part of the process resources. – Martin James Nov 11 '14 at 20:15
  • 1
    @Jim: what do you mean, "then how" ? Threads are implemented as threads. Each thread belongs to a process. – Harry Johnston Nov 11 '14 at 21:01

1 Answers1

1

Threads in modern versions of Java are "native" and are implemented, scheduled and handled by the OS the JVM is running on. So the answer depends on which OS you are using.

Distinguishing between Java threads and OS threads?

EDIT

In general, not just java, the rules for how threads are created is determined by the language, the OS and and language libraries that are used (or some combination of those).

But in general, on modern OSes, multiple threads often share a single process for performance reasons. Threads are sometimes called light weight processes.

This link has an overview of threads and C libraries for writing multithreaded apps for various OSes.

Community
  • 1
  • 1
dkatzel
  • 31,188
  • 3
  • 63
  • 67
  • What does the term native mean?Also please note that this question is not specific to Java.Unless you are trying to say that the thread implementation depends both in the OS *and* the language – Jim Nov 10 '14 at 19:16
  • native means ...um..."locally born". In this context a native thread is something that the OS creates – dkatzel Nov 10 '14 at 19:19
  • Yes but does that mean that this is an implementation detail and the OS could create processes or via some other way? – Jim Nov 10 '14 at 19:20
  • @Jim depends on the language. Something higher level like Java - it's an implementation detail. Something lower level, you might have more control – dkatzel Nov 10 '14 at 19:31