[Python-Dev] Bugs in thread_nt.h

Sturla Molden sturla at molden.no
Thu Mar 10 04:15:35 CET 2011


Den 10.03.2011 03:02, skrev Mark Hammond:
> These issues are best put in the tracker so they don't get lost - 
> especially at the moment with lots of regulars at pycon.
>
  Ok, sorry :-)


> It would also be good to know if there is an actual behaviour bug 
> caused by this (ie, what problems can be observed which are caused by 
> the current code?)

None that I have observed, but this is required according to MSDN.

Theoretically, an optimizing compiler could cache the 'owned' field if 
it's not declared volatile. It currently works because a wait on the 
lock is implemented with a WaitForSingleObject on a kernel event object 
when the waitfalg is set. If the wait mechanism is changed to a much 
less expensive user-space spinlock, just releasing the time-slice by 
Sleep(0) for each iteration, it will certainly fail without a volatile 
qualifier.

As for InterlockedCompareExchange et al., MSDN says this: "The 
parameters for this function must be aligned on a 32-bit boundary; 
otherwise, the function will behave unpredictably on multiprocessor x86 
systems and any non-x86 systems. See _aligned_malloc."

Well, it does not hurt to obey :-)

Regards,
Sturla





More information about the Python-Dev mailing list