Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Lwt mean "Light Weight Thread"?

Tags:

ocaml

ocsigen

I have been testing ocsigen which uses Lwt. I guess Lwt means "Light Weight Thread",right? If so, how can we call it "light weight" ?

It seems Lwt is using OS's thread which is NOT light (compared with Erlang and Haskell).

Please shed a light on me, thanks!

like image 866
z_axis Avatar asked Aug 08 '12 00:08

z_axis


1 Answers

Yes, Lwt means lightweight threads and Lwt's threads are light. Lwt has a cooperative threading model, only a single lwt thread runs at the same time on a single system thread, until it explictely yields control. It's your duty to make sure your computation eventually yields otherwise other lwt threads may never run.

However Lwt also has a pool of system threads used to execute blocking system calls or to delegate your long running functions so that they dont't block the whole system and prevent other lwt threads from running.

You can find out more about Lwt's model and implementation in this paper (which you can get on the original author's web page, here).

like image 87
Daniel Bünzli Avatar answered Oct 01 '22 19:10

Daniel Bünzli