- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 gcc,我在编译使用 ucontext.h 的东西时遇到这些错误
/usr/include/sys/ucontext.h: At top level:
/usr/include/sys/ucontext.h:138: error: expected identifier or ‘(’ before numeric constant
/usr/include/sys/ucontext.h:139: error: expected ‘;’ before ‘stack_t’
查看 ucontext.h,这似乎是导致的原因:
134 /* Userlevel context. */
135 typedef struct ucontext
136 {
137 unsigned long int uc_flags;
138 struct ucontext *uc_link;
139 stack_t uc_stack;
140 mcontext_t uc_mcontext;
141 __sigset_t uc_sigmask;
142 struct _libc_fpstate __fpregs_mem;
143 } ucontext_t;
第 138 行和 139 行如何引发这些错误?不知道该怎么做,因为这是一个标准的 sys header 。
最佳答案
这个问题可能是由于代码中某处的#define
将uc_link定义为某个整数引起的。
例子:
#define uc_link 22
在 Unix/Linux 中找到它的最有效方法是在源代码目录上运行 grep -r "uc_link".
。如果您使用 git 来管理您的源代码,您可以使用 git grep "uc_link"
代替。
如果此定义存在于一个文件中,并且您在其中使用了 ucontext.h,那么您应该尝试将 ucontext 逻辑与需要此 #define
的逻辑分离。
此外,我必须指出,#define
不是 ALL_CAPS 是一种不好的做法。您遇到的问题很好地体现了其中一个原因,另一个原因是每个人都希望它们是 ALL_CAPS,而您的代码对于可能希望与您合作的其他程序员而言变得更难理解和可读。
关于包含 ucontext.h 时无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20665478/
我问的平台是linux。我说的线程本地存储是gcc中的pthread_xxx或__thread。 我想在我的程序中使用 ucontext 东西,即 makecontext、swapcontext 等。
我读到 ucontext 用于在 linux 中保存多个线程之间的上下文。既然OS做的是不同线程之间的上下文切换,为什么linux要提供这个头文件(ucontext.h)来进行上下文切换呢? 最佳答案
Boost v1.59 中的 Boost.Context 文档报告了以下性能比较结果: +----------+----------------------+-------------------+-
使用 gcc,我在编译使用 ucontext.h 的东西时遇到这些错误 /usr/include/sys/ucontext.h: At top level: /usr/include/
cygwin 似乎不支持用户上下文切换(由 ucontext.h 支持)。 鉴于我需要在 cygwin 下开发一个用户上下文切换应用程序,有什么解决方案吗? 最佳答案 您可能可以编写自己的实现,环绕
我正在尝试将使用 ucontext 的库移植到支持 pthread 但不支持 ucontext 的平台。代码写得很好,因此用对 pthread 例程的调用替换对 ucontext API 的所有调用应
中的用户线程函数已弃用,因为它们使用了已弃用的 C 功能(它们 use a function declaration with empty parentheses for an argument )
所以我正在尝试解除分配上下文。 这是我创建上下文的方式 ucontext* uPtr = new ucontext; getcontext(uPtr); char* stack = new char[
当我在下面编译我的代码时,它会打印 I am running :) 永远(直到我向程序发送 KeyboardInterrupt 信号), 但是当我取消注释 //printf("done:%d\n",
这里是代码,不知道每个detain是什么意思,比如REG_RIP,什么是“RIP” //ucontext.h enum { //... REG_RIP, //... } here是完整代码 最佳答
我正在为操作系统类(class)做一个项目。任务是实现一个处理线程的库,类似于 pthreads,但要简单得多。它的目的是练习调度算法。最终产品是一个 .a 文件。类(class)结束,一切正常(在功
作为更大的线程调度 api 的一部分,这是我想做的事情。 我想创建一个线程,当主线程(创建线程的线程)退出时,我刚创建的线程应该执行。我正在尝试使用 ucontext 和 uc_link 执行此操作,
我去年学习了操作系统,期间我使用用户上下文(在头文件 ucontext.h 中定义)为一个项目实现线程调度程序(其中每个线程模拟一个进程)。我正在参加一个讲座,将讨论用户上下文,我突然想到,尽管去年完
嗨,我需要从一个地方跳到另一个地方... 但我想知道哪个更好用,setjmp 或 ucontext,例如: setjmp 和 ucontext 是否可移植? 我的代码使用这些库是线程安全的吗? 为什么
据我所知,ucontext 提供了比 setjmp 更好的东西。但它已被弃用,现在已从 POSIX 规范中删除。那么它为什么会出现,又为什么会被移除? 最佳答案 makecontext的签名来自 uc
我正在设计一个具有以下功能的调度算法: 在一个进程中有 2 个用户线程(上下文)(我应该做 3 个线程,但在 osx 上还不起作用,所以我决定现在让 2 个工作) 使用每 1 秒关闭一次的 SIGAL
我正在使用 ucontext 开发一个简单的、具有教育意义的绿色(合作)基于量子的线程示例。但我面临着问题。下面提供的示例非常容易理解,我将感谢您为我提供的任何帮助: TestApp.java: pu
我的代码在这里: #define _GNU_SOURCE #include "lib-ult.h" #include #include #include #include #define TR
我有这个最小的 helloworld,扩展了 ucontext.h: #include #include int main(int argc, char** argv) { printf ("
我正在尝试使用 ucontext 例程来实现多线程库。运行此代码时出现“浮点异常(核心已转储)”。 #include #include #include typedef struct {
我是一名优秀的程序员,十分优秀!