[Numpy-discussion] Threading question for Travis

Travis E. Oliphant oliphant at enthought.com
Sat Apr 26 13:21:01 EDT 2008


Charles R Harris wrote:
> Travis,
>
> Is this correct?
>
Yes.
>     NPY_LOOP_BEGIN_THREADS;
>     switch(loop->meth) {
>     case ONE_UFUNCLOOP:
>         /*
>          * Everything is contiguous, notswapped, aligned,
>          * and of the right type.  -- Fastest.
>          * Or if not contiguous, then a single-stride
>          * increment moves through the entire array.
>          */
>         /*fprintf(stderr, "ONE...%d\n", loop->size);*/
>         loop->function((char **)loop->bufptr, &(loop->size),
>                 loop->steps, loop->funcdata);
>         UFUNC_CHECK_ERROR(loop);
>         break;
>
> Note that UFUNC_CHECK_ERROR calls PyErr_Occurred. That doesn't seem 
> thread safe to me. Or maybe there is something special about that 
> function I'm missing.
Check the definition of the macro.   It only calls PyErr_Occurred if the 
obj variable is non-zero on the loop structure, indicating an 
OBJECT-array loop.    In that case, the NPY_LOOP_BEGIN_THREADS does not 
actually release the GIL either.

-Travis




More information about the NumPy-Discussion mailing list