- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
关于像这样应用于 cdef extern 的“nogil”,有一件事我不完全理解:
cdef extern from "pthread.h" nogil:
ctypedef struct pthread_mutex_t:
pass
cdef int pthread_mutex_init(pthread_mutex_t *, void *)
cdef int pthread_mutex_destroy(pthread_mutex_t *)
我不清楚那个 nogil 的效果,我在 Cython 的文档中找不到任何关于它的信息。我的解释是,在内部声明的函数隐含了 nogil。我对吗?那么结构呢?
感谢您提供任何信息。
最佳答案
来自 Cython docs关于与 C 代码的绑定(bind)
The nogil function annotation declares that it is safe to call the function without the GIL.
在您的示例中,这意味着 with nogil
block 中允许使用函数 pthread_mutex_init
和 pthread_mutex_destroy
。在没有显式 with nogil
block 的情况下,GIL 仍然存在:有必要但不足以像示例中那样声明函数。
普通 C 变量可以在 nogil block 中使用,但您要对线程安全负责。
关于python - cdef extern from ... 诺吉尔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49162218/
在不牺牲 cdef 调用程序中的 cdef 的情况下,他们有什么方法可以使这项工作正常进行吗? (也没有使用 cpdef) from array import * from numpy import
我正在学习 Cython,现在正在试验它。我尝试了基本的 cdef 类示例程序,它运行良好。 现在我想做的是在 cdef 类类型中混合使用 cdef 和非 cdef 属性,就像这样 cdef clas
我正在尝试在 cython 中实现通用排序算法。因此,我创建了以下模块,它在 sorter_t 类中实现了 Heapsort 算法: # file general_sort_c.pyx from li
我想要一个 cdef 类的 cython 数组: cdef class Child: cdef int i def do(self): self.i += 1 cdef
当我声明一个返回 double 的 cdef 函数时,我会写 cdef double method_name(...) 。如果它没有返回任何东西并且我只是将它省略给 cdef method_name(
我在同一个模块的所有函数中使用了很多相同类型的变量: def func1(double x): cdef double a,b,c a = x b = x**2 c =
我有一个使用许多 nogil cdef 函数的应用程序,我想对它们进行分析为了找到瓶颈。 我尝试将 profile=True 指令传递给 Cython,但这些函数似乎是免疫的,因此 cProfile.
感谢 stackoverflow 上的一些人,我终于让 cython 工作了,但现在有一个问题。从我不使用 cdef 到我使用 cdef 确实没有速度提升。不要误会我的意思,当我使用 cython 编
关于像这样应用于 cdef extern 的“nogil”,有一件事我不完全理解: cdef extern from "pthread.h" nogil: ctypedef struct pt
我想要一个 cdef 类的 cython 数组: cdef class Child: cdef int i def do(self): self.i += 1 cdef
我想知道在声明函数时def、cdef 和cpdef 之间的区别。def 和其他 def 之间的区别或多或少是清楚的。而且我还看到,有时它会在声明中添加返回类型 (cdef void/double/in
我正在尝试在运行 Alpine 的 Docker 镜像上编译一些代码。但是,gcc 由于 fatal error: sys/cdefs.h: No such file or directory 而不断
常设问题: 为什么 Cython 编译中的其他错误指向特定的错误行,而这个却没有? 更新前: 由于难以编译扩展类型,正如下面“不会编译”链接中所引用的,人们认为 AssertionError 与扩展类
是否有一种 cython-ic 方法可以将 cdef 数组设置为零。我有一个具有以下签名的函数: cdef cget_values(double[:] cpc_x, double[:] cpc_y):
我正在尝试改进此使用列表类型的代码: # CLASS ORDERC # ################ cdef class OrderC: cdef int _side cdef
我很好奇以下内容是否有效,其中只有部分变量在类型声明的类中进行了类型声明。也就是说,在这种情况下,类之前的 cdef 会无效吗? cdef class CythonClass: cdef in
我有一个 cdef 函数返回一个 (int, int) 元组。我需要传播异常,因此必须为异常指定返回类型。由于我的函数从不返回负值,这可能例如是 (-1, -1)。使用 documentation 中
class Myuser * MyClient_GetMyUser(AUser aUser); 这是尝试使用 ffi.cdef 声明该函数的错误: Error: dllImport.lua:861:
尝试使用 XCode 在 Mac Lion (10.7) 上编译我的 C++ 应用程序时,我一直遇到错误。编译器提示 cdefs.h 中的一行(包含在 syslog.h 中)带有错误 expected
我已经使用 cdef 定义了一个 python 类,它用 Cython 包装了一个 C++ 类并且它工作正常。但是,当我在 python 或类中使用 help(class) 时?在 ipython 中
我是一名优秀的程序员,十分优秀!