java - 如何使用 sched_setaffinity 清除线程关联性,这意味着我想将控制权交还给内核?

标签 java linux kernel real-time jna

我到处寻找,但似乎无法完成。我试图避免的是:

“通过 fork(2) 创建的子级继承其父级的 CPU 亲和性掩码。”

来源:https://manpages.debian.org/testing/manpages-dev/sched_setaffinity.2.en.html

最佳答案

您只需将关联性设置回“所有可用处理器”即可。

一种选择可能是计算所有逻辑处理器的数量并使用该位掩码,但它可以更简单,如 the man page包括这些有用的评论(强调我的):

After a call to sched_setaffinity(), the set of CPUs on which the process will actually run is the intersection of the set specified in the mask argument and the set of CPUs actually present on the system. The system may further restrict the set of CPUs on which the process runs if the "cpuset" mechanism described in cpuset(7) is being used. These restrictions on the actual set of CPUs on which the process will run are silently imposed by the kernel.

因此,您可以发送一个 0xffff... 位掩码,方便地,它是整数 -1。我建议使用 long 值 -1,但如果您知道系统的处理器数量少于 32 个,则可以使用 int

关于java - 如何使用 sched_setaffinity 清除线程关联性,这意味着我想将控制权交还给内核?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61808102/

相关文章:

java - 使用巨大的 ArrayLists,Java OutOfMemoryError : Java heap space. .. 使用 db?

c - Linux 中匿名内存映射映射到哪个文件?

Java函数Else问题

java - `new Object()' 好像没有创建新对象,为什么?

linux - 如何在Linux中安装urwfonts-8.71.tar.bz2?

php - Apache 无法访问我的主目录中的文件夹

unix - xv6 KERNBASE 限制进程内存

windows - 在 Windows 内核地址空间中将虚拟地址转换为物理地址

kernel - 在 4.9 内核驱动程序中使用唤醒锁

java - 使注释处理器读取 Maven 更新上的 src/main/resources 文件的方法