[Python-checkins] python/dist/src/Misc NEWS,1.807,1.808

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Thu, 03 Jul 2003 21:40:47 -0700


Update of /cvsroot/python/python/dist/src/Misc
In directory sc8-pr-cvs1:/tmp/cvs-serv23219/Misc

Modified Files:
	NEWS 
Log Message:
An Anonymous Coward on c.l.py posted a little program with bizarre
behavior, creating many threads very quickly.  A long debugging session
revealed that the Windows implementation of PyThread_start_new_thread()
was choked with "laziness" errors:

1. It checked MS _beginthread() for a failure return, but when that
   happened it returned heap trash as the function result, instead of
   an id of -1 (the proper error-return value).

2. It didn't consider that the Win32 CreateSemaphore() can fail.

3. When creating a great many threads very quickly, it's quite possible
   that any particular bootstrap call can take virtually any amount of
   time to return.  But the code waited for a maximum of 5 seconds, and
   didn't check to see whether the semaphore it was waiting for got
   signaled.  If it in fact timed out, the function could again return
   heap trash as the function result.  This is actually what confused
   the test program, as the heap trash usually turned out to be 0, and
   then multiple threads all got id 0 simultaneously, confusing the
   hell out of threading.py's _active dict (mapping id to thread
   object).  A variety of baffling behaviors followed from that.

WRT #1 and #2, error returns are checked now, and "thread.error: can't
start new thread" gets raised now if a new thread (or new semaphore)
can't be created.  WRT #3, we now wait for the semaphore without a
timeout.

Also removed useless local vrbls, folded long lines, and changed callobj
to a stack auto (it was going thru malloc/free instead, for no discernible
reason).

Bugfix candidate.


Index: NEWS
===================================================================
RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v
retrieving revision 1.807
retrieving revision 1.808
diff -C2 -d -r1.807 -r1.808
*** NEWS	1 Jul 2003 21:12:47 -0000	1.807
--- NEWS	4 Jul 2003 04:40:44 -0000	1.808
***************
*** 11,14 ****
--- 11,25 ----
  -----------------
  
+ - The Windows implementation of PyThread_start_new_thread() never
+   checked error returns from Windows functions correctly.  As a result,
+   it could claim to start a new thread even when the Microsoft
+   _beginthread() function failed (due to "too many threads" -- this is
+   on the order of thousands when it happens).  In these cases, the
+   Python exception ::
+ 
+       thread.error: can't start new thread
+ 
+   is raised now.
+ 
  Extension modules
  -----------------