|
|
|
|
|
by qznc
4865 days ago
|
|
Agreed. I tried to benchmark the context switching of user-level threads vs kernel-level threads [0]. Specifically, libtask vs pthread. I assumed, pthread_yield would be very expensive, because it has to do a syscall into the kernel. Something like an order of magnitude or two. Interestingly, with two threads switching back and forth was only two times as slow as the user-level threads. Linux futexes seem to be really clever. Use them! On the other hand, pthread_yield scales linearly, while libtask has a constant time yield. So for concurrency without parallelism [1] and lots of threads, the libtask library can be recommended. [0] https://bitbucket.org/qznc/switchcost/src [1] http://existentialtype.wordpress.com/2011/03/17/parallelism-... |
|