链接 pthread 函数 pthread_condattr_setclock 的 NPTL
我编写了一些在条件变量上使用定时等待的 pthread 代码,但为了确保相对等待,我使用 pthread_condattr_setclock() 将 condvar 的时钟类型设置为 CLOCK_MONOTONIC。
为了在 RHEL4 上编译和链接 pthread_condattr_setclock(),我必须将 -I/usr/include/nptl 和 -L/usr/lib/nptl 添加到我的 gcc 命令行中。我的理解是,2.6 内核(RHEL4 具有)默认使用 NPTL pthread 实现,那么为什么我需要显式指定这些路径才能使用此功能?
只有这个函数需要我这样做:如果我省略它,则所有内容都可以正常编译和链接,而无需指定额外的路径(尽管代码的行为是不正确的)。
I've written some pthread code that use timed waits on a condition variable but in order to ensure a relative wait I've set the condvar's clock type to CLOCK_MONOTONIC using pthread_condattr_setclock().
In order to compile and link pthread_condattr_setclock() on RHEL4, i've had to add -I/usr/include/nptl and -L/usr/lib/nptl to my gcc command line. My understanding is that the 2.6 kernel (which RHEL4 has) uses the NPTL pthread implementation by default so why do I need to specify these paths explicitly to use this function?
It's only this function that requires me to do this: if I leave it out, everything compiles and links fine without the extra paths specified (although the behaviour of the code is then incorrect).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知, /usr/include 和 /usr/lib 中的 pthread 标头和库分别是旧的 LinuxThreads 实现,我的假设是它们是为了向后兼容(即您应该针对旧接口进行构建) )但在运行时使用 NPTL 实现(其接口是 LinuxThreads 接口的超集)。
因此,只有当您知道需要新的 NPTL 接口(即,如果您需要一些额外的功能),并且最重要的是,您知道 NPTL 接口将在运行时可用时,您才能使用它。
From what I been able to find out, the pthread header and library in /usr/include and /usr/lib respectively are the old LinuxThreads implementations and my supposition is that they are there for backwards compatability (i.e. you should build against the old interface) but at run time the NPTL implementation is used (which has an interface that is a superset of the LinuxThreads interface).
Therefore, you can only use the new NPTL interface (i.e. if you require some extra functionality) if you know that you need it and, crucially, you know that the NPTL interface will be available at runtime.