3 ms·
> What kind of overhead do OS thread have that green thread doesn't ? I'm aware of the stack size, but is there something else ? Real context switches (with ca
by toast0 10y ago
> What kind of overhead do OS thread have that green thread doesn't ? I'm aware of the stack size, but is there something else ?
Real context switches (with cache invalidation) to switch between, system call (with context switch to kernel) to create/dispose, probably kernel bits that will explode with huge thread lists: I wouldn't be surprised if listing all threads with ps or top also locks the thread lists: not a big deal if you have a reasonable number of threads, but could block thread creation in a 1M thread case.
- pcwalton 10y agoContext switches are really fast on modern x86.
- Jweb_Guru 10y agoPlus there are specialized hardware instructions for them, and the expensive parts (saving weird registers etc.) are fast-pathed in Linux if they're not being used.
- toast0 10y ago> Context switches are really fast on modern x86. Not context switching is even faster. How fast is really fast, how modern is modern? some results from 2010 [1] show at least 1000 nanoseconds per context switch (even with optimizations for the kernel switching between threads of the same process). That's not that slow, but it is a lot of time you could be doing something else. [1] http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-ma... [1] http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-make-context.html http://blog.tsunanet.net/2010/11/how-long-does-it-take-to-ma...