[Numpy-discussion] numpy error handling

Andrew Straw strawman at astraw.com
Sat Apr 1 15:56:03 CST 2006


Tim Hochberg wrote:

> Travis Oliphant wrote:
>
>>
>> One question I have with threads and error handling though?  Right
>> now, the ufuncs release the Python lock during computation (and
>> re-acquire it to do error handling if needed).   If another ufunc was
>> started by another Python thread and ran with different error
>> handling, wouldn't the IEEE flags get confused about which ufunc was
>> setting what?  The flags are only checked after each 1-d loop.  If
>> another thread set the processor flag, the current thread could get
>> very confused.
>>
>> This seems like a problem that I'm not sure how to handle. 
>
>
> Yeah, me either. It seems that somehow we'll need to block until all
> current operations are done, but I don't know how to do that off the
> top of my head. Perhaps ufuncs need to lock the flags when they start
> and release them when they finish. This looks feasible, but I'm not
> sure of the proper incantation to get this right. The ufuncs would all
> need to be able able to increment and decrement the lock, whatever it
> is, even though they are in different threads. Meanwhile the setting
> code should only be able to work when the lock is unheld. It's some
> sort of poly thread recursive lock thing. I'll think about it, perhaps
> there's an obvious way.


I am also absolutely no expert in this area, but isn't this exactly what
the kernel supports multiple threads for? In other words, I'm not sure
we have to worry about it at all. I expect that the kernel sets/restores
the CPU/FPU error flags on thread switches and this is part of the cost
associated with switching threads. As I understand it, linux threads are
actually implemented as new processes, so if we did have to be worried
about this, wouldn't we also have to be worried that program A might
alter the FPU error state while we're also using program B?

This is just my unsophisticated and possibly wrong understanding of
these things. If anyone can help clarify the issue, I'd be glad to be
enlightened.

Cheers!
Andrew




More information about the Numpy-discussion mailing list