GNU Pth for User-Space Context
2014-02-23 18:55
387 查看
User-Space Context
The following functions provide a stand-alone sub-API for user-space context switching. It internally is based on the same underlying machine context switching mechanism the threads in GNU Pth are based on. Hence these functions you can use for implementing
your own simple user-space threads. The pth_uctx_t context is somewhat modeled after POSIX ucontext(3).
The time required to create (via pth_uctx_make(3)) a user-space context can range from just a few microseconds up to a more dramatical time (depending on the machine context switching method which is available on the platform). On the other hand, the raw performance
in switching the user-space contexts is always very good (nearly independent of the used machine context switching method). For instance, on an Intel Pentium-III CPU with 800Mhz running under FreeBSD 4 one usually achieves about 260,000 user-space context
switches (via pth_uctx_switch(3)) per second.
int pth_uctx_create(pth_uctx_t *uctx);
This function creates a user-space context and stores it into uctx. There is still no underlying user-space context configured. You still have to do this with pth_uctx_make(3). On success, this function returns TRUE, else FALSE.
int pth_uctx_make(pth_uctx_t uctx, char *sk_addr, size_t sk_size, const sigset_t *sigmask, void (*start_func)(void *), void *start_arg, pth_uctx_t uctx_after);
This function makes a new user-space context in uctx which will operate on the run-time stack sk_addr (which is of maximum size sk_size), with the signals in sigmask blocked (if sigmask is not NULL) and starting to execute with the call start_func(start_arg).
If sk_addr is NULL, a stack is dynamically allocated. The stack size sk_size has to be at least 16384 (16KB). If the start function start_func returns and uctx_after is not NULL, an implicit user-space context switch to this context is performed. Else (if
uctx_after is NULL) the process is terminated with exit(3). This function is somewhat modeled after POSIX makecontext(3). On success, this function returns TRUE, else FALSE.
int pth_uctx_switch(pth_uctx_t uctx_from, pth_uctx_t uctx_to);
This function saves the current user-space context in uctx_from for later restoring by another call to pth_uctx_switch(3) and restores the new user-space context from uctx_to, which previously had to be set with either a previous call to pth_uctx_switch(3)
or initially by pth_uctx_make(3). This function is somewhat modeled after POSIX swapcontext(3). If uctx_from or uctx_to are NULL or if uctx_to contains no valid user-space context, FALSE is returned instead of TRUE. These are the only errors possible.
int pth_uctx_destroy(pth_uctx_t uctx);
This function destroys the user-space context in uctx. The run-time stack associated with the user-space context is deallocated only if it was not given by the application (see sk_addr of pth_uctx_create(3)). If uctx is NULL, FALSE is returned instead of
TRUE. This is the only error possible.
来源: http://www.gnu.org/software/pth/pth-manual.html
The following functions provide a stand-alone sub-API for user-space context switching. It internally is based on the same underlying machine context switching mechanism the threads in GNU Pth are based on. Hence these functions you can use for implementing
your own simple user-space threads. The pth_uctx_t context is somewhat modeled after POSIX ucontext(3).
The time required to create (via pth_uctx_make(3)) a user-space context can range from just a few microseconds up to a more dramatical time (depending on the machine context switching method which is available on the platform). On the other hand, the raw performance
in switching the user-space contexts is always very good (nearly independent of the used machine context switching method). For instance, on an Intel Pentium-III CPU with 800Mhz running under FreeBSD 4 one usually achieves about 260,000 user-space context
switches (via pth_uctx_switch(3)) per second.
int pth_uctx_create(pth_uctx_t *uctx);
This function creates a user-space context and stores it into uctx. There is still no underlying user-space context configured. You still have to do this with pth_uctx_make(3). On success, this function returns TRUE, else FALSE.
int pth_uctx_make(pth_uctx_t uctx, char *sk_addr, size_t sk_size, const sigset_t *sigmask, void (*start_func)(void *), void *start_arg, pth_uctx_t uctx_after);
This function makes a new user-space context in uctx which will operate on the run-time stack sk_addr (which is of maximum size sk_size), with the signals in sigmask blocked (if sigmask is not NULL) and starting to execute with the call start_func(start_arg).
If sk_addr is NULL, a stack is dynamically allocated. The stack size sk_size has to be at least 16384 (16KB). If the start function start_func returns and uctx_after is not NULL, an implicit user-space context switch to this context is performed. Else (if
uctx_after is NULL) the process is terminated with exit(3). This function is somewhat modeled after POSIX makecontext(3). On success, this function returns TRUE, else FALSE.
int pth_uctx_switch(pth_uctx_t uctx_from, pth_uctx_t uctx_to);
This function saves the current user-space context in uctx_from for later restoring by another call to pth_uctx_switch(3) and restores the new user-space context from uctx_to, which previously had to be set with either a previous call to pth_uctx_switch(3)
or initially by pth_uctx_make(3). This function is somewhat modeled after POSIX swapcontext(3). If uctx_from or uctx_to are NULL or if uctx_to contains no valid user-space context, FALSE is returned instead of TRUE. These are the only errors possible.
int pth_uctx_destroy(pth_uctx_t uctx);
This function destroys the user-space context in uctx. The run-time stack associated with the user-space context is deallocated only if it was not given by the application (see sk_addr of pth_uctx_create(3)). If uctx is NULL, FALSE is returned instead of
TRUE. This is the only error possible.
来源: http://www.gnu.org/software/pth/pth-manual.html
相关文章推荐
- Clob类型转换成String类型
- linux iscsi initiator 安装配置
- C++中临时量做参数的特点
- Clob类型转换成String类型
- Clob类型转换成String类型
- Clob类型转换成String类型
- 再说Activity的四种启动模式
- 编写一个代表学生的Student类
- java实现mysql的连接
- php的抽象类与接口
- shell (1)
- 浙大PAT 1070题 1070. Mooncake
- 大数据带来的安全新挑战
- poj2112 二分+floyd+多源多汇最大流
- poj2112 二分+floyd+多源多汇最大流
- (转载)Java里快如闪电的线程间通讯
- ubuntu中查找安装文件的目录(包括lib, include, 可执行文件路径)
- 【数据库】BAT文件登录MySQL及SQL查询命令精解
- BNU 看风景 27585
- POJ 3469最大流最小割原理(Dinic多路增广)