How multithreading works in hardware using D ==AND== difference b/w goroutine and threads in D

Paulo Pinto pjmlp at progtools.org
Sun Nov 25 11:37:56 PST 2012


Am 25.11.2012 20:29, schrieb Sparsh Mittal:
> Hello
>
> I could find this for Java, but not yet for D and so wanted to ask:
>
> Would you tell briefly, how multi-threading in D works on hardware. What
> I wanted to ask is: if we have a single-core or multicore system, how
> does scheduling of threads in D happens.
>
> For Java, what I found was (in my words):
>
> The JVM runs as a single process which internally spawns many threads.
> When the scheduler code running inside the JVM asks for another thread,
> JVM starts another thread. The execution of the threads is done using
> timeslicing, which enables threads to share the processor. With this
> approach, concurrency using multithreading can be achieved even on
> single processors. On multicore platforms, these threads can possibly be
> scheduled on different CPU cores. In hardware, the management of thread
> is done by the operating system (OS), and the JVM uses the facility
> provided by the OS.
>
>
> My second question is: What is the difference between working of
> goroutine in Go and threads spawned in D. Both work concurrently with
> the caller (parent).
>
> Correct me wherever wrong.
>
> My interest in D and Go is using them for parallelizing scientific
> applications.
>
>


Your explanation for Java is not fully correct. The JVMs are free to 
make use of green threads, also know as user space threads, in such 
cases you don't have really a 1:1 mapping to OS threads and scheduling
is limited to blocking operations. Although most VMs nowadays make use
of real threads.

In D's case, it depends. If you are making use of threading APIs 
directly then you have 1:1 mapping to OS threads, but if you use actors
or std.parallelism module, then you have a N:1 mapping between tasks and 
OS threads.

D developers please correct me, if I am wrong.

--
Paulo


More information about the Digitalmars-d mailing list