Feature request: ability to use libeio with multiple event loops

Marc Lehmann schmorp at schmorp.de
Thu Dec 22 03:02:35 CET 2011

On Wed, Dec 21, 2011 at 09:38:01PM +0100, Hongli Lai <hongli at phusion.nl> wrote:
> > Well, threads were originally invented because single cpus only had a single
> > set of registers, and swapping these can be costly (especially with vm
> > state).
> I agree with your assertion that single CPUs had a single set of
> registers and that swapping registers can be costly. But what does
> this have to do with the invention of threads? Are you saying that by
> using threads, CPUs do not have to swap registers?

With threads, you can avoid swapping some registers, most notably the MMU
registers, which are often very costly to swap, to the extent that a number
of cpus even have extra support for multiple "contexts".

> Are you talking about hardware simultaneous multithreading
> (http://en.wikipedia.org/wiki/Simultaneous_multithreading), e.g.
> HyperThreading?

No, just distant history, try
http://en.wikipedia.org/wiki/Thread_%28computer_science%29 if you like

   Until late 1990s, CPUs in desktop computers did not have much support
   for multithreading, although threads were still used on such computers
   because switching between threads was generally still quicker than full
   process context switches.

(that page isn't completely relevant though, as it is talking about a much
more general thread concept as we do here).

Basically, you could have slow process switching and faster thread
switching, which lead to the relative dominance of threads on both solaris
and windows nt (both suffering fro slow process switchign much more so
than linux).

Slightly related, even in 2011, schedulers suck - when I run 5 processes
that use 100% cpu on my 4-core box, I end up with one completely idle core
on linux.

Or benchmark libeio with one core (taskset) or multiple ones, and you'll
see it's much faster with only one available core.

Or better yet, benchmark eventfd vs. a pipe on one/two cores. The results are
not nice.

Reality is far from perfect, and threads are far less wlel optimised than
they should be.

> Let me get this right before continuing the discussion. Are you saying
> that this program (in pseudo code):

Thats not all I am saying, but I would say that for these programs, yes.

                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\

More information about the libev mailing list