<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type><!-- flashmail style begin -->
<STYLE type=text/css>
body {border-width:0;margin:0}
img {border:0;margin:0;padding:0}
</STYLE>
<BASE target=_blank><!-- flashmail style end -->
<META name=GENERATOR content="MSHTML 11.00.10240.16603"></HEAD>
<BODY 
style="BORDER-LEFT-WIDTH: 0px; FONT-SIZE: 10.5pt; FONT-FAMILY: 微软雅黑; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; COLOR: #000000; MARGIN: 12px; LINE-HEIGHT: 1.5; BORDER-TOP-WIDTH: 0px" 
marginheight="0" marginwidth="0">
<DIV>I think the multi-threaded cases are not really problems. The race 
condition only happens when another thread closed the file descriptor, and 
the only knowing case of closing file descriptors without knowing what they do 
is during fork (daemon) process. It always produces unpredictable results 
if you fork with multiple threads without planning anyway. For GIL, I think it 
is acceptable for PyPy to be different with CPython in very rare cases. Users 
should understand they have different implement details. It is only important 
that common use cases like python-daemon works as expected.</DIV>
<DIV> </DIV>
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; COLOR: #c0c0c0" 
align=left>2015-12-28 
<HR id=SignNameHR 
style="BORDER-TOP: #c0c0c0 1px solid; HEIGHT: 1px; BORDER-RIGHT: 0px; WIDTH: 122px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px" 
align=left>
<SPAN id=_FlashSignName>hubo</SPAN> </DIV>
<HR 
style="BORDER-TOP: #c0c0c0 1px solid; HEIGHT: 1px; BORDER-RIGHT: 0px; BORDER-BOTTOM: 0px; BORDER-LEFT: 0px">

<BLOCKQUOTE id=ntes-flashmail-quote 
style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; PADDING-LEFT: 0px; MARGIN-LEFT: 0px">
  <DIV><STRONG>发件人:</STRONG>Armin Rigo <arigo@tunes.org></DIV>
  <DIV><STRONG>发送时间:</STRONG>2015-12-27 07:42</DIV>
  <DIV><STRONG>主题:</STRONG>Re: [pypy-dev] Dead loop occurs when using 
  python-daemon and multiprocessing together in PyPy 4.0.1</DIV>
  <DIV><STRONG>收件人:</STRONG>"Vincent 
  Legoll"<vincent.legoll@gmail.com></DIV>
  <DIV><STRONG>抄送:</STRONG>"pypy-dev"<pypy-dev@python.org></DIV>
  <DIV> </DIV>
  <DIV>
  <DIV>Hi Vincent, </DIV>
  <DIV> </DIV>
  <DIV>On Sat, Dec 26, 2015 at 1:45 PM, Vincent Legoll </DIV>
  <DIV><vincent.legoll@gmail.com> wrote: </DIV>
  <DIV>> OK, I understand we want to have behavior as identical to cpython as possible. </DIV>
  <DIV>> </DIV>
  <DIV>> So does that mean implementing the same : "fstat() & check we're still </DIV>
  <DIV>> on the same inode & device as before" ? </DIV>
  <DIV>> Do we also need to do the "could have been opened in another thread" dance ? </DIV>
  <DIV>> And what about the CLO_EXEC thing, this does seem sensible to do too, </DIV>
  <DIV> </DIV>
  <DIV>This is what I started to do, but I stopped because there are </DIV>
  <DIV>additional issues on PyPy: you need to make sure that the GIL is not </DIV>
  <DIV>released at places where CPython does not release it either. </DIV>
  <DIV>Otherwise, you're opening the code to "race conditions" again. </DIV>
  <DIV> </DIV>
  <DIV>The goal would be to be *at least* as safe as CPython.  There are a </DIV>
  <DIV>lot of corner cases that are not discussed in the source code of </DIV>
  <DIV>CPython.  I'm pretty sure that some of them are possible (but rare). </DIV>
  <DIV>As an extreme example, if one thread does os.urandom() and another </DIV>
  <DIV>thread does os.close(4) in parallel, where 4 happens to be the file </DIV>
  <DIV>descriptor returned by open() in urandom.c, then it is possible that </DIV>
  <DIV>the open()'s result is closed after open() but before urandom.c </DIV>
  <DIV>reacquires the GIL.  Then urandom.c gets a closed file descriptor.  If </DIV>
  <DIV>additionally the other thread (or a 3rd one) opens a different file at </DIV>
  <DIV>file descriptor 4, then urandom.c will think it successfully opened </DIV>
  <DIV>/dev/urandom but actually the file descriptor is for some unrelated </DIV>
  <DIV>file.  However, this is probably an issue that cannot be dealt with at </DIV>
  <DIV>all on Posix even in C.  That would mean that it is always wrong to </DIV>
  <DIV>close() unknown file descriptors from one thread when other threads </DIV>
  <DIV>might be running...  This would not hurt being clarified. </DIV>
  <DIV> </DIV>
  <DIV> </DIV>
  <DIV>A bientôt, </DIV>
  <DIV> </DIV>
  <DIV>Armin. </DIV>
  <DIV>_______________________________________________ </DIV>
  <DIV>pypy-dev mailing list </DIV>
  <DIV>pypy-dev@python.org </DIV>
  <DIV>https://mail.python.org/mailman/listinfo/pypy-dev </DIV></DIV></BLOCKQUOTE></BODY></HTML>