- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚将我的项目上传到github: https://github.com/gitlwh/whyisthis/tree/master
您可以克隆它并在 Mac 上运行。这很方便。当我在根文件夹中运行 make
时,它显示:
uthread.c:21:3: warning: implicit declaration of function ‘swapcontext’ [-Wimplicit-function-declaration]
swapcontext(¤tThread->context,&scheduler_context);
^
uthread.c: In function ‘main_manager’:
uthread.c:31:2: warning: implicit declaration of function ‘setcontext’ [-Wimplicit-function-declaration]
setcontext(&mainThread->context);
^
uthread.c: In function ‘initialer’:
uthread.c:72:5: warning: implicit declaration of function ‘getcontext’ [-Wimplicit-function-declaration]
getcontext(&initThread->context);
^
uthread.c: In function ‘THREAD_INIT’:
uthread.c:112:3: warning: implicit declaration of function ‘makecontext’ [-Wimplicit-function-declaration]
makecontext(&mainThread->context, (void(*)(void)) main_manager, 0, NULL, NULL);
^
我在网上查找了很多资料,并用 sys/ucontext.h 替换了 ucontext.h。我实在不知道这是为什么。
更新:如果我更改为 ucontext.h,它将显示:
uthread.c: In function ‘signal_handler’:
uthread.c:21:3: warning: ‘swapcontext’ is deprecated [-Wdeprecated-declarations]
swapcontext(¤tThread->context,&scheduler_context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:40:6: note: declared here
int swapcontext(ucontext_t * __restrict, const ucontext_t * __restrict) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘main_manager’:
uthread.c:31:2: warning: ‘setcontext’ is deprecated [-Wdeprecated-declarations]
setcontext(&mainThread->context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:39:6: note: declared here
int setcontext(const ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c:32:2: warning: ‘setcontext’ is deprecated [-Wdeprecated-declarations]
setcontext(&scheduler_context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:39:6: note: declared here
int setcontext(const ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘thread_manager’:
uthread.c:43:2: warning: ‘setcontext’ is deprecated [-Wdeprecated-declarations]
setcontext(&scheduler_context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:39:6: note: declared here
int setcontext(const ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘scheduler’:
uthread.c:55:9: warning: ‘swapcontext’ is deprecated [-Wdeprecated-declarations]
swapcontext(&scheduler_context,¤tThread->context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:40:6: note: declared here
int swapcontext(ucontext_t * __restrict, const ucontext_t * __restrict) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘initialer’:
uthread.c:72:5: warning: ‘getcontext’ is deprecated [-Wdeprecated-declarations]
getcontext(&initThread->context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:37:6: note: declared here
int getcontext(ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘THREAD_INIT’:
uthread.c:112:3: warning: ‘makecontext’ is deprecated [-Wdeprecated-declarations]
makecontext(&mainThread->context, (void(*)(void)) main_manager, 0, NULL, NULL);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:38:6: note: declared here
void makecontext(ucontext_t *, void (*)(), int, ...) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘THREAD_CREATE’:
uthread.c:138:3: warning: ‘makecontext’ is deprecated [-Wdeprecated-declarations]
makecontext(&newThread->context, (void(*)(void)) thread_manager, 2, func, arg);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:38:6: note: declared here
void makecontext(ucontext_t *, void (*)(), int, ...) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c:143:3: warning: ‘getcontext’ is deprecated [-Wdeprecated-declarations]
getcontext(&mainThread->context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:37:6: note: declared here
int getcontext(ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c:157:3: warning: ‘getcontext’ is deprecated [-Wdeprecated-declarations]
getcontext(&newThread->context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:37:6: note: declared here
int getcontext(ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c:169:3: warning: ‘makecontext’ is deprecated [-Wdeprecated-declarations]
makecontext(&newThread->context, (void(*)(void)) thread_manager, 2, func, arg);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:38:6: note: declared here
void makecontext(ucontext_t *, void (*)(), int, ...) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c:172:3: warning: ‘swapcontext’ is deprecated [-Wdeprecated-declarations]
swapcontext(¤tThread->context,&scheduler_context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:40:6: note: declared here
int swapcontext(ucontext_t * __restrict, const ucontext_t * __restrict) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘THREAD_EXIT’:
uthread.c:209:2: warning: ‘setcontext’ is deprecated [-Wdeprecated-declarations]
setcontext(&scheduler_context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:39:6: note: declared here
int setcontext(const ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c: In function ‘THREAD_YIELD’:
uthread.c:217:5: warning: ‘getcontext’ is deprecated [-Wdeprecated-declarations]
getcontext(¤tThread->context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:37:6: note: declared here
int getcontext(ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
uthread.c:221:9: warning: ‘setcontext’ is deprecated [-Wdeprecated-declarations]
setcontext(&scheduler_context);
^
In file included from uthread.h:8:0,
from uthread.c:1:
/usr/include/ucontext.h:39:6: note: declared here
int setcontext(const ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;
^
最佳答案
On MAC OS, you should replace
ucontext.h
withsys/ucontext.h
? Also, it seems you need to do same thing with many packages.
没有;你不应该替换 <ucontext.h>
与 <sys/ucontext.h>
; macOS 手册非常清楚,您应该使用 #include <ucontext.h>
违背这一点将会导致问题。
您使用什么编译选项?
header 包含#ifdef _XOPEN_SOURCE
然后定义函数,但还有一个 #else
条款说
#error The deprecated ucontext routines require _XOPEN_SOURCE to be defined
因此,在 macOS 上,最好不要使用这些函数,但不要使用 swapcontext()
的标题或手册页。说首选的替代方案是什么(假设有替代方案),这很令人恼火。如果您确实想使用 ucontext
功能,必须保证_XOPEN_SOURCE
是在编译时定义的。您可以直接在命令行上或通过 header 执行此操作。 (我使用自己的 header posixver.h
来完成该任务;您可以在目录 https://github.com/jleffler/soq/tree/master/src/libsoq 中找到它的副本。)
Compiling with
-D_XOPEN_SOURCE
now gives warnings about the function being deprecated — what can I do about that?
该函数已被标记为已弃用,并且在使用它时会收到警告,因为它已已弃用 - 但该函数现在已声明。如果您不想要弃用警告,请添加 -Wno-deprecated-declarations
到编译器选项。或者重写代码以使用其他机制来管理您正在使用 swapcontext()
所做的任何事情。 。
请注意,编译器会告诉您哪个选项触发了警告,以便您可以抑制它,如 no-
所示。字首。您还可以使用-Werror=deprecated-declarations
强制其成为错误而不是警告。如果编译器不包含消息中那样的标志名称,您可能无法抑制警告或错误。
关于c - Mac OS 上函数 ‘swapcontext’ 的隐式声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41752086/
我正在尝试使用 swapcontext() 创建一个简单的 hello world 示例 这是代码片段: #include #include #include static ucontext_t
首先,让我为代码“示例”的长度表示歉意,我试图提供尽可能小的可执行示例。 我应该提到,队列的形式为: 当调用 run 时,第一个元素被成功地从队列中删除,然后由全局指针 Curr_Thread 引用。
基本上,我正在尝试做的是在具有上下文切换的单个线程上模拟多线程。我每 10 微秒设置一个警报,然后将上下文从一个线程切换到另一个线程。问题是大约五分之一的运行在警报完成 swapcontext 后立即
我正在构建一个抢占式用户空间线程调度程序,它使用计时器来中断线程并根据优先级在线程之间切换。然而,一旦一个线程被中断,我似乎就不能让它完成;只能重新开始。我所要求的甚至可以使用 swapcontext
我正在做一个进行 unix 系统调用的项目。具体而言,我的项目严重依赖对 getcontext()、makecontext()、swapcontext() 和 setcontext() 的调用。我尝试
我对上下文切换很感兴趣。我已将示例代码复制到文件中 http://pubs.opengroup.org/onlinepubs/009695399/functions/makecontext.html
我刚刚将我的项目上传到github: https://github.com/gitlwh/whyisthis/tree/master 您可以克隆它并在 Mac 上运行。这很方便。当我在根文件夹中运行
在 unix 环境中,makecontext()/swapcontext() 函数系列有时用于在 C 中实现协程。然而,这些函数直接操作堆栈和执行流。当从 C 切换到 C++ 时,这些低级功能通常有很
int swapcontext(ucontext_t *oucp, ucontext_t *ucp); int getcontext(ucontext_t *ucp); int setcontext(
我已成功使用 makecontext/swapcontext 移动堆栈。但是,当我尝试将它与 pthread_mutex_lock 或 pthread_mutex_unlock 一起使用时,我总是
我正在使用通常的 makecontext/swapcontext 例程,用 C 语言编写一个小型的概念验证 Fiber 库,但这给我带来了一些麻烦(我的平台是 OSX 10.9 Mavericks,使
我们需要实现一个线程库。但我真的无法解决这个 yield() 函数......所以在 yield() 中,我们需要将当前线程推到就绪线程队列的末尾,并将第一个线程弹出并执行它。(FIFO)我使用的是
我是一名优秀的程序员,十分优秀!