3 ms·
Threads aren't really fast. The fact that you have a shared VM space allows you to avoid the cost of swapping page tables (and flushing any logically-addressed
by cperciva 17y ago
Threads aren't really fast. The fact that you have a shared VM space allows you to avoid the cost of swapping page tables (and flushing any logically-addressed cache) but you still have to store and restore the entire architectural state, which can easily take a few hundred cycles on systems with lots of registers. Co-routines are much faster, since they allow the compiler to optimize away handling of state which it knows isn't important.
... oh wait, wrong type of threads.
- jrockway 17y agoIncidentally, the only usable Perl threads are implemented on top of coroutines: http://search.cpan.org/~mlehmann/Coro-5.22/Coro.pm http://search.cpan.org/~mlehmann/Coro-5.22/Coro.pm Just don't read the rant about why call/cc is useless.