[Pyrex] Pyrex and the GIL
Andrew Bennetts
andrew-pyrex at puzzling.org
Wed Sep 7 06:16:33 CEST 2005
On Wed, Sep 07, 2005 at 03:58:26PM +1200, Greg Ewing wrote:
> Simon Burton wrote:
>
> >And inversely: some syntax to indicate that a particular c function
> >call can release the GIL.
>
> That's actually where I came from initially on this.
> I was thinking of having a declaration like
>
> cdef extern int foo(int blarg) nogil
>
> where "nogil" means "this function expects the GIL to be
> released when it is called". Whenever it is called in a
> Pyrex function, code would be generated to release the
> GIL, call the function, and then re-acquire the GIL.
I'd call this acquire_gil, or perhaps acquires_gil.
> Then I realised that the *same* declaration could be
> used the other way round, too. If you write
>
> cdef void my_callback() nogil
> ...code here...
>
> you're saying "the GIL will be released when this
> function is called". So Pyrex will generate code to
> acquire the GIL before executing the function body
> and release it again afterward.
And then I'd call this one releases_gil.
> Is that neat? Or too confusing?
I think it is perhaps a little too confusing. I think
acquires_gil/releases_gil is clearer and more descriptive, but I haven't
spent a huge amount of effort thinking about it.
-Andrew.
More information about the Pyrex
mailing list