I'm looking into writing a userland threading library, since there seems to be no active work in this area, and I believe the C++0x promises and futures may give this model some power. Unfortunately, in order to make this model work, it i开发者_运维问答s essential to ensure a context switch on blocking calls. As such, I would like to intercept every syscall in order to replace it with an asynchronous version. There are some caveats:
- I know there are asynchronous syscalls for just about every regular syscall, but for backwards compatibility reasons this is not a viable solution.
- I know that in Linux 2.4 or earlier it was possible to directly change the sys_call_table, but this has vanished.
- As I would like my library to be statically linked if desired, the LD_PRELOAD trick isn't viable.
- Similarly, kernel modules are not an option because this is supposed to be a userland library.
- Finally, ptrace() is also not an option for similar reasons. I can't have my library forking a new process just in order to be used.
Is this possible?
I'm looking into writing a userland threading library, since there seems to be no active work in this area
You might want to take a look at the thread libraries Marcel (and its publications) and MPC, which implement hybrid (kernel and user-level) threads, mainly in the purpose of High-Performance Computing, so they had to find some solution for this blocking system calls.
So as to avoid the blocking of kernel threads when the application makes blocking system calls, Marcel uses Scheduler Activations when they are available, or just intercepts such blocking calls at dynamic symbols level.
精彩评论