Two Hundred Threads One Core

A service uses an N:1 green-thread library: 200 application threads are multiplexed onto a single kernel thread by a user-space scheduler on an 8-core machine. Every application thread does a blocking read() on its own socket. More than one statement below is true. Select every true one.

A

Each of the 200 threads still needs its own kernel stack, so per-thread memory is comparable to an equivalent number of pthread_create threads.

B

A page fault taken by one thread is invisible to the others, unlike a blocking read(), because the fault is resolved without descheduling the kernel thread.

C

The 200 threads together occupy at most one of the 8 cores at any instant.

D

The moment any one thread issues its blocking read(), all 200 stop running, because the kernel sees a single schedulable entity and puts it to sleep.

E

Switching between two of these threads is a register save plus a stack pointer swap in user space, with no kernel entry and no privilege transition.

F

The fix is to put the sockets in non-blocking mode and drive them from an event loop, so the user-space scheduler runs another thread instead of parking the kernel thread.