secret of light-weight user thread

Kazu Yamamoto ( 山本和彦 ) kazu at iij.ad.jp
Tue Sep 6 10:47:29 CEST 2011


Hello,

Recently I exchanged information about user threads with Ruby
community in Japan.

The user threads of Ruby 1.8 are heavy weight and Ruby 1.9 switched to
kernel threads. The reason why user threads of Ruby 1.8 are heavy
weight is *portability*. Since Ruby community does not want to prepare
assembler to change stack pointers for each supported CPU
architecture, Ruby 1.8 copies the stack of user threads on context
switch.

Because I need to explain why the user threads of GHC are light
weight, I gave a look at GHC's source code and found the
loadThreadState function in compiler/codeGen/StgCmmForeign.hs. In this
function, the stack pointer is changed in the Cmm level.

So, my interpretation is as follows: Since GHC has Cmm backend, it is
easy to provide assembler to change stack pointers for each supported
CPU architecture. That's why GHC can provide light weight user
threads.

Is my understanding correct?

Thanks in advance.

--Kazu



More information about the Glasgow-haskell-users mailing list