Light-weight threads

Robert Jacques sandford at jhu.edu
Wed Feb 24 19:34:23 PST 2010


On Wed, 24 Feb 2010 21:08:02 -0500, sybrandy <sybrandy at gmail.com> wrote:

>> Norbert, you are confusing threads with fibers. OS Threads have never
>> been, nor will ever be, "light-weight" in any sense of the word. If they
>> were, no one would care about thread-pools and the like. Languages that
>> feature light-weight threads, such as Erlang, are actually spawning
>> fibers. The Erlang runtime, for example, only ever uses one D style
>> thread to host millions of 'logical' threads.
>
> Actually, newer versions of Erlang now use multiple threads, typically 1  
> per CPU and one pool of processes and a scheduler per thread.  Processes  
> can also be moved between threads in case one is busier than the others.
>
> Casey

I looked into this 1 or 2 years ago. Erlang was designed for the cluster,  
so they just use multiple processes (1 per CPU) not multiple threads.  
There's very little little overhead to this technique and it was a simple,  
elegant and trivial solution. Besides there are a lot of pitfalls to going  
to a true multi-threaded runtime, not the least of which is the GC. There  
are a lot of technical issues which make moving fibers between threads  
very dangerous: doing so requires you to be aware of all the operations  
you can't use/do and to program around them accordingly. Otherwise you end  
up with data races.



More information about the Digitalmars-d mailing list