python - Malloc 与 nogil 一起使用安全吗?

标签 python c++ c malloc cython

在cython中用malloc和nogil分配内存安全吗? 在 nogil 运行的多线程程序中传递指针是否安全?

最佳答案

GIL 到位是因为 CPython 内存管理不是 thread-safe .因此,在您与 Python 对象(即由 Python 处理的内存)交互的情况下,您可以使用 nogil

这在文档中提到 for releasing the GIL :

Code in the body of the statement must not manipulate Python objects in any way, and must not call anything that manipulates Python objects without first re-acquiring the GIL. Cython currently does not check this.

因此,只要不涉及 Python 对象,使用 malloc、传递指针和做任何在 C 中合法的事情都是绝对安全的。

关于python - Malloc 与 nogil 一起使用安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36528510/

相关文章:

c - 网络掩码转换,有什么问题?

python - root.destroy() 和 root.quit() 有什么区别?

python ,Gtk3 : How to make the Progress bar pulsing while other stuffs are running

c++ - 在Linux中,等效于在c/c++中打开物理驱动器的句柄并写入MBR的方法是什么?

c++ - 未解析的重载类型>[int] 用于数组下标 c++

c - 如何逐个字符读取文件,然后将它们存储到动态分配的数组中

c - 编译 p3dfft 驱动程序时未解析的 MPI Fortran 符号

python - 清除字典但保留 key

python - 在 OS X 上使用 Django 加载 MySQLdb 模块时出错

c++ - C++中全局与本地包含文件的顺序如何