本帖最后由 yulihua49 于 2019-12-15 19:47 编辑
正确的说,不是C++,而是在哪个操作系统。
LINUX有,ucontext,我已经用了好几年了。
man makecontext 试试看
MAKECONTEXT(3) Linux Programmer's Manual MAKECONTEXT(3)
NAME makecontext, swapcontext - manipulate user context
SYNOPSIS #include <ucontext.h>
void makecontext(ucontext_t *ucp, void (*func)(), int argc, ...);
int swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
DESCRIPTION In a System V-like environment, one has the type ucontext_t defined in <ucontext.h> and the four functions getcontext(3), setcontext(3), makecontext() and swapcon- text() that allow user-level context switching between multiple threads of control within a process.
For the type and the first two functions, see getcontext(3).
The makecontext() function modifies the context pointed to by ucp (which was obtained from a call to getcontext(3)). Before invoking makecontext(), the caller must allocate a new stack for this context and assign its address to ucp->uc_stack, and define a successor context and assign its address to ucp->uc_link.
When this context is later activated (using setcontext(3) or swapcontext()) the function func is called, and passed the series of integer (int) arguments that follow argc; the caller must specify the number of these arguments in argc. When this function returns, the successor context is activated. If the successor context pointer is NULL, the thread exits.
The swapcontext() function saves the current context in the structure pointed to by oucp, and then activates the context pointed to by ucp.
RETURN VALUE When successful, swapcontext() does not return. (But we may return later, in case oucp is activated, in which case it looks like swapcontext() returns 0.) On error, swapcontext() returns -1 and sets errno appropriately.
ERRORS ENOMEM Insufficient stack space left.
VERSIONS makecontext() and swapcontext() are provided in glibc since version 2.1.
|