[Python-Dev] Bugs in thread_nt.h

"Martin v. Löwis" martin at v.loewis.de
Thu Mar 10 16:02:02 CET 2011


> I am sorry for misreading 32 bits (4 bytes) as 32 bytes. That is
> obviously very different. If Microsoft's malloc is sufficient, why does
> MSDN tell us to use _aligned_malloc instead of malloc?

I don't know. Perhaps they assume that people may be using alternative
malloc implementations, or (more likely) people in the platform group
are unaware of the guarantees the compiler group makes (because of
compliance with the C standard).

> Obvious usecases for volatile are:
>
> - Implementation of a spinlock, where register allocation is detrimental.

Unfortunately, that's not true. It's not really possible to implement
a spinlock in C if the processor can make changes to the write ordering.

> - A buffer that is filled from the "outside" with some DMA mechanism.
> - Real-time programs and games where order of execution and and timing
> is critical, so optimization must be supressed.

Likewise. On many current processors, you have to use fencing 
instructions to make this kind of stuff work, something that the 
compiler will not normally generate (except through inline assembly).

> Even though volatile is not needed for processing within a critical
> section, we still need the shared data to be re-loaded upon entering and
> er-written upon leaving.

Please see the code. Where exactly does such reloading/rewriting need to 
happen?

Regards,
Martin


More information about the Python-Dev mailing list