Christian Schubert <b...@apexo.de> added the comment:

added a patch which fixes both issues

before releasing the GIL we take a copy of the ufds pointer and its len, 
erasing the ufds pointer in the poll object (to make sure nobody else fiddles 
with it); when we're done we either but it back into the object (when it's 
still NULL) or we free it

the update logic is modified as well, since the uptodate flag is not sufficient 
anymore, we now count up a tag for each modification of the poll dictionary and 
remember that tag together with the ufds pointer

the result is:
- for the single-threaded case we do little extra work (moving ufds from/to 
poll object)
- correct for the multi-threaded case, with slightly higher overhead (one 
additional call to each of malloc, update_ufd_array, free), probably worse than 
having one poll object per thread, but not worse than allocating a new poll 
object each time we want to poll

there still is potential for incorrect poll results (but not for memory 
corruption): when poll_register/poll_unregister are called exactly 2**32 times 
(or multiples thereof) while poll_poll is running, it will happily put back its 
outdated ufds pointer into the poll object when its done, this could be 
alleviated by changing tag to long long ... which is unlikely to wrap around 
anytime soon.

----------
keywords: +patch
Added file: http://bugs.python.org/file17675/select.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8865>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to